我遇到动态选择器的问题。这是我的代码
var data = {
'one': {'value': '50,60,70,80'},
'two': {'value': '10,20,30,40'}
}
var eachValue = data.one.value.split(',');
该代码正在纠正但我需要one
two
的动态选择器,所以如果我的代码像
var select = 'one';
var eachValue = data.select.value.split(',');
它不起作用。它显示TypeError: data.select is undefined
错误。那我怎么能在这里使用动态选择器呢。感谢
答案 0 :(得分:1)
如果要将变量用作属性名称var data = {
'one': {'value': '50,60,70,80'},
'two': {'value': '10,20,30,40'}
}
var select = 'two';
var eachValue = data[select].value.split(',');
console.log(eachValue)
$(function(){
$("#exampleModal2").foundation('open');
$('.nav').click(function(){
if($(this).hasClass('prev')){
if($(".reveal-overlay:visible").prev().find('.reveal').length){
$(".reveal-overlay:visible").prev().find('.reveal').foundation('open');
} else{
$(".reveal-overlay:last").find('.reveal').foundation('open');
}
}else{
if($(".reveal-overlay:visible").next().find('.reveal').length){
$(".reveal-overlay:visible").next().find('.reveal').foundation('open');
}else{
$(".reveal-overlay:first").find('.reveal').foundation('open');
}
}
});
});