$.each(json.people, function (key, val) {
for (k in this) tHead += "<td class='bg_thead pl_10'>" + this[k] + "</td>";
});
改为
$.each(json.people[0], function (key, val) {
for (k in this) tHead += "<td class='bg_thead pl_10'>" + this[k] + "</td>";
});
for (k in this) tHead += "<td class='bg_thead pl_10'>" + this[k] + "</td>";
});
改为
$.each(json.people[0], function (key, val) {
for (k in this) tHead += "<td class='bg_thead pl_10'>" + this[k] + "</td>";
});
$.each(json.people, function (key, val) {
for (k in val) tHead += "<td class='bg_thead pl_10'>" + this[k] + "</td>";
});
这样?
$("#tbItem thead").append(tHead);
alert($("#tbItem thead").html());
加这句看看dom有元素没有,有就是和#9说的,第一列被隐藏了,firebug或者chrome开发工具看看有什么css作用到那个元素上了,或者被其他js代码移除了
方法一:var json = { "people": { "Col01": "姓名","Col02": "手机"}};改成这样,不要采用数据,省得还得取个下村
$(function(){
var json = { "people": { "Col01": "姓名","Col02": "手机"}},
tHead = "<tr><td class='bg_thead pl_10'>序号</td>";
$.map(json.people,function(v){
tHead += "<td class='bg_thead pl_10'>" + v + "</td>";
});
tHead += "</tr>";
alert(tHead);
$("#tbItem thead").append(tHead);});方法二:var json = { "people": ["姓名","手机","身份证"]};直接使用数组,反正你那些什么Col01什么的都没用到过
$(function(){
var json = { "people": ["姓名","手机","身份证"]},
tHead = "<tr><td class='bg_thead pl_10'>序号</td><td class='bg_thead pl_10'"
+ json.people.join("</td><td class='bg_thead pl_10'>")
+ "</td></tr>";
alert(tHead);
$("#tbItem thead").append(tHead);
})
<script type="text/javascript">
$(function(){
var json = { "people": ["姓名","手机","身份证"]},
tHead = "<tr><td class='bg_thead pl_10'>序号</td><td class='bg_thead pl_10'>"
+ json.people.join("</td><td class='bg_thead pl_10'>")
+ "</td></tr>";
alert(tHead);
$("#tbItem thead").append(tHead);
})
</script>
<table id="tbItem">
<thead>
</thead>
</table>