为表格添加数据
2016-06-26 15:25
369 查看
html: <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> <script src="producte.js"> </script> </head> <body> <table border="1" width="300"> <caption>商品信息</caption> <thead> <tr> <th>商品名</th> <th>单价</th> <th>厂家</th> <th>品牌属性</th> </tr> </thead> <tbody id="myTable"></tbody> </table> </body> </html> JavaScript代码: /** * Created with JetBrains WebStorm. * User: liu * Date: 16-6-21 * Time: 下午1:19 * To change this template use File | Settings | File Templates. */ window.onload = function(){ var str =""; var myTableMsg = document.getElementById("myTable"); for(var i = 0; i < producte.length; i++){ var obj = producte[i]; str +="<tr>" + "<td>"+obj.productName+"</td>" + "<td>"+obj.price+"</td>" + "<td>"+obj.make+"</td>" + "<td>"+obj.shuxing+"</td>" + "</tr>" myTableMsg.innerHTML = str; } } var producte = [{"productName":"opple",price:2500,make:"opple公司",shuxing:"手机"}, {"productName":"Mi",price:2500,make:"小米公司",shuxing:"手机"}, {"productName":"三星",price:2500,make:"三星公司",shuxing:"手机"}, {"productName":"华为",price:2500,make:"华为公司",shuxing:"手机"}, {"productName":"apple",price:2500,make:"苹果公司",shuxing:"手机"}];
相关文章推荐
- linux下shell显示-bash-4.1#不显示路径解决方法
- IDEA之创建不了.java文件解决
- JS禁止选中文本方法
- 决策树(ID3,C4.5)Python实现
- Is the Name of This Problem
- Note On <You Don't Know JS - this and Object Prototypes>
- Android 访问res目录下的资源
- StepView(步骤流程的view)
- CMAKE 学习
- 字符编码常识
- MyBatis传入集合 list 数组 map参数的写法
- Lua中的正则表达式及源码分析
- 久久发营销软件站
- jquery课堂笔记
- Jquery联表
- Mac下添加java环境变量
- 好想建立自己的博客网站
- <<联盟>>:雇主与员工的新型关系笔记
- mybatis 批量插入
- Adapter类型控件之AutoCompleteTextView(自动完成文本框)&MultiAutoCompleteTextView(多提示项的自动完成文本框)