Posted in Javascript onSeptember 22, 2020
看到网上有很多朋友问遍历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数组的实现代码的文章就介绍到这了,更多相关jQuery 遍历json数组内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!
jQuery 遍历json数组的实现代码
- Author -
mdxy-dxy声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@