如何调用json模拟数据中的数据并输出到html的table中? 50
varper={name:"王五",age:"15",class:"五班"};<tableid=“table”><tr><td>输入到这里</td></tr></tabl...
var per={name:"王五",age:"15",class:"五班"};
<table id=“table”>
<tr>
<td>输入到这里
</td>
</tr>
</table> 展开
<table id=“table”>
<tr>
<td>输入到这里
</td>
</tr>
</table> 展开
2个回答
展开全部
<script type="text/javascript">
var per={name:"王五",age:"15",class:"五班"};
document.getElementsByTagName('td')[0].innerHTML = per.name;
</script>
追问
如果per里面有两组{name:"李四",age:"18",class:"三班"};{name:"王五",age:"15",class:"五班"}; 我想通过在input里面搜索 李四 然后 把李四的 年龄 班级 名字输出到table里面。应该怎么操作?
展开全部
<div class="box"></div>
<script type="text/javascript">
$(function(){
//1.数据准备
var arr=[{"name":"小王","age":22,"sex":"girl"},{"name":"小李","age":22,"sex":"girl"},{"name":"小郑","age":22,"sex":"girl"},{"name":"小 张","age":22,"sex":"girl"},{"name":"小马","age":22,"sex":"girl"},{"name":"小蓝","age":22,"sex":"girl"},{"name":"小菜","age":22,"sex":"girl"},{"name":"小鹿","age":22,"sex":"girl"},]
//2.抓取
var res="";
for(var uu=0;uu<arr.length;uu++){
if(arr[uu].name=="小蓝"){
break;
}
res+='<ul><li>'+arr[uu].name+'</li><li>'+arr[uu].age+'</li><li>'+arr[uu].sex+'</li></ul>';
}
//3.展示
$(".box").html(res);
})
</script>
<script type="text/javascript">
$(function(){
//1.数据准备
var arr=[{"name":"小王","age":22,"sex":"girl"},{"name":"小李","age":22,"sex":"girl"},{"name":"小郑","age":22,"sex":"girl"},{"name":"小 张","age":22,"sex":"girl"},{"name":"小马","age":22,"sex":"girl"},{"name":"小蓝","age":22,"sex":"girl"},{"name":"小菜","age":22,"sex":"girl"},{"name":"小鹿","age":22,"sex":"girl"},]
//2.抓取
var res="";
for(var uu=0;uu<arr.length;uu++){
if(arr[uu].name=="小蓝"){
break;
}
res+='<ul><li>'+arr[uu].name+'</li><li>'+arr[uu].age+'</li><li>'+arr[uu].sex+'</li></ul>';
}
//3.展示
$(".box").html(res);
})
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询