我对 jQuery 很陌生,我不明白为什么这个循环不显示对象属性。
如果你能帮助我,我将不胜感激。
var shop_array = ["title","price","img","text"];
var submit = $(".add").find(":submit");
submit.on("click",function(e){
var elements = $(".add").children(':input');
for(var i=0;i<elements.length;i++){
if($(elements[i]).val()!==""){
var object = '\"'+shop_array[i]+'\"';
console.log(shopcart.shop_values[object])//dosen't display shop_value;
console.log(object);
}
}
});
var shopcart= {
shop_values :{
"title":"a",
"price":"b",
"img":"img",
"text":"text"
},
add: function(){
}
}