相思资源网 Design By www.200059.com

看到网上有很多朋友问遍历json数组的代码,特为大家整理了一些,需要的朋友可以看下。

<script type="text/javascript"> 
var d1 =[{"text":"王家湾","value":"9"},{"text":"李家湾","value":"10"},{"text":"邵家湾","value":"13"}]; 
$(d1).each(function(){ 
alert(this.text+" "+this.value); 
}); 
</script> 

不用JQuery

<script type="text/javascript"> 
var json = {"options":"[{\"text\":\"王家湾\",\"value\":\"9\"},{\"text\":\"李家湾\",\"value\":\"10\"},{\"text\":\"邵家湾\",\"value\":\"13\"}]"} 
json = eval(json.options) 
for(var i=0; i<json.length; i++) 
{ 
alert(json[i].text+" " + json[i].value) 
} 
</script> 

js遍历json数组

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> New Document </TITLE> 
<META NAME="Generator" CONTENT="EditPlus"> 
<META NAME="Author" CONTENT=""> 
<META NAME="Keywords" CONTENT=""> 
<META NAME="Description" CONTENT=""> 
<script language="javascript"> 
function e() 
{ 
var json=[{"kl_id":"2","kl_title":"Test date","kl_content":"Test date","kl_type":"1","id":"1"},{"kl_id":"2","kl_title":"Test","kl_content":"Test","kl_type":"1","id":"2"}] 
var str = ""; 
for (var one in json) 
{ 
for(var key in json[one]) 
{ 
str += json[one][key] + ","; 
} 
} 
document.form.txtName.value = str; 
} 
</script> 
</HEAD> 

<BODY> 
<form name="form"> 
<a href="#" onclick="e();">Click</a> 
<br> 
<input name="txtName" value="" type="text" size="50"> 
</form> 
</BODY> 
</HTML> 
标签:
jQuery,遍历,json,数组

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“jQuery 遍历json数组的实现代码”

暂无jQuery 遍历json数组的实现代码的评论...