<div class="codetitle"> <span><a style="CURSOR: pointer" data="24307" class="copybut" id="copybut24307" onclick="doCopy('code24307')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code24307"> <br><script type="text/javascript"> <BR>var d1 =[{"text":"王家湾","value":"9"},{"text":"李家湾","value":"10"},{"text":"邵家湾","value":"13"}]; <BR>$(d1).each(function(){ <BR>alert(this.text+" "+this.value); <BR>}); <BR></script> <br> </div> <br>不用JQuery <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="2281" class="copybut" id="copybut2281" onclick="doCopy('code2281')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code2281"> <br><script type="text/javascript"> <BR>var json = {"options":"[{\"text\":\"王家湾\",\"value\":\"9\"},{\"text\":\"李家湾\",\"value\":\"10\"},{\"text\":\"邵家湾\",\"value\":\"13\"}]"} <BR>json = eval(json.options) <BR>for(var i=0; i<json.length; i++) <BR>{ <BR>alert(json[i].text+" " + json[i].value) <BR>} <BR></script> <br> </div> <br><strong>js遍历json数组</strong> <br><div class="htmlarea"> <textarea id="runcode49950"> <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> <form name="form"> <a href="#" onclick="e();">Click</a> <input name="txtName" value="" type="text" size="50"> </form> </textarea><br><input onclick="runEx('runcode49950')" type="button" value="运行代码"> <input onclick="doCopy('runcode49950')" type="button" value="复制代码"> <input onclick="doSave(runcode49950)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>