js json for的问题 for循环不出param_+key
发布网友
发布时间:2024-10-04 07:30
我来回答
共3个回答
热心网友
时间:2024-10-12 22:26
/*
如下:
*/
<script type="text/javascript">
<!--
obj={
"title": "title",
"pages": "13",
"count": 15,
"param_0": "0",
"param_1": "1",
"param_2": "2",
"param_3": "3",
"param_4": "4",
"param_5": "5",
"param_6": "6",
"param_7": "7",
"param_8": "8",
"param_9": "9",
"param_10": "10",
"param_11": "11",
"param_12": "12",
"param_13": "13",
"param_14": "14"
};
for (var key = 0; key <= obj.count; key++){
alert(eval("obj.param_"+key));
}
//-->
</script>
热心网友
时间:2024-10-12 22:23
我写的答案竟然说有什么不合法字符。够郁闷的,只能用图片发了,希望管理员看到后处理一下,为什么我写的文字发不出去。
热心网友
时间:2024-10-12 22:23
var obj={"title":"title","pages":"13","count":15,"param_0":"0","param_1":"1","param_2":"2","param_3":"3","param_4":"4","param_5":"5","param_6":"6","param_7":"7","param_8":"8","param_9":"9","param_10":"10","param_11":"11","param_12":"12","param_13":"13","param_14":"14"};
for (var key = 0; key <= obj.count; key++){
eval("alert(obj.param_"+key+")");
}
你试试这样,你的那句alert(obj[0].param_+key);意思是弹出obj[0].param_和key的和,和你要的意思不同,所以你要用eval来执行表达式