猿问

一直搞不懂闭包问题,这次开发真的遇上了,求解决办法,要求各product分别展示出各自的属性

$(document).ready(function(){
functionproduct(name,description,price){
this.name=name;
this.des=description;
this.price=price;
}
varproduct1=newproduct("iphone","手机",3200);
varproduct2=newproduct("huawei","手机",1800);
varproduct3=newproduct("nicai","手机",998);
varproduct4=newproduct("sansung","手机",3000);
varproduct5=newproduct("opera","手机",2000);
varproducts=[product1,product2,product3,product4,product5];
for(varj=0;jvarpname=document.getElementsByClassName("pname")[j];
varpdes=document.getElementsByClassName("pdes")[j];
varpprice=document.getElementsByClassName("pprice")[j];
for(vari=0;ipname.innerHTML=products[i].name;
pdes.innerHTML=products[i].des;
pprice.innerHTML=products[i].price;
}
}
});
RISEBY
浏览 407回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答