js高手帮我看看 jquery 怎么遍历获取 data-* 的值?
html中:<divid="area"data-area='{"area1":"1","area2":"2","area3":"3","area4":"5"}'></di...
html 中:
<div id="area" data-area='{"area1":"1","area2":"2","area3":"3","area4":"5"}'></div>
js中:
var ctl = $("#area");
var level = 4;
var areaid = ctl.data('area');
for (var i = 1; i <= level; i++) {
var str= areaid.area+i;
}
我现在要逐一获取areaid.area1、areaid.area3、areaid.area3、areaid.area4的值。
该怎么处理呢? 展开
<div id="area" data-area='{"area1":"1","area2":"2","area3":"3","area4":"5"}'></div>
js中:
var ctl = $("#area");
var level = 4;
var areaid = ctl.data('area');
for (var i = 1; i <= level; i++) {
var str= areaid.area+i;
}
我现在要逐一获取areaid.area1、areaid.area3、areaid.area3、areaid.area4的值。
该怎么处理呢? 展开
展开全部
var ctl = $("#area");
var level = 4;
var areaid = ctl.data('area');
for (var i = 1; i <= level; i++) {
alert(areaid["area"+i]);
}
var ctl = $("#area");
var areaid = ctl.data('area');
for(var item in areaid){
alert(item + ": " + areaid[item]);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询