我希望该函数隐藏价格超过150的每个元素。我编写了从容器中制作商品的脚本。现在我要进行价格分类,因此onclick仅显示例如150以下的项目。
var ItemCollection =
[
{
Name: 'IVY PA',
Price: 160,
Picture: 'some pic'
},
{
Name: 'IVY P',
Price: 100,
Picture: 'some pic'
},
];
ItemCollection.forEach(generateItem);
$('#Collection').append(content);
var content = "";
function generateItem(item, index, arrays) {
content = content + '\n' +
' <li class="Shoe"><a href="#' + item.Name + '\'">\n' +
' <div>\n' +
' <img class="ItemPicture"\n' +
' src=" ' + item.Picture + '">\n' +
'\n' +
' </div>\n' +
' <div class="ItemInfo">\n' +
' <p>' + item.Name + '</p>\n' +
' <p>' + item.Price + '$</p>\n' +
' </div>\n' +
' </a>\n' +
' </li>\n';
}
function under150() {
var price = "";
var Shoe = document.getElementsByClassName("Shoe");
price = ItemCollection.item.Price;
console.log(ItemCollection.item.Price);
if (price > 150){
Shoe.style.display = "none";
}
else {}
}
目前有我的尝试,但是我知道这是完全错误的,我需要一点帮助,因此,如果您有任何想法,我将非常感谢。
迭代每个项目,然后检查价格,如果价格大于150,则隐藏该特定项目。
function under150() {
var Shoe = document.getElementsByClassName("Shoe");
for(var i=0;i<Shoe.length;i++)
{
price = ItemCollection[i].Price;
if (price > 150){
Shoe[i].style.display = "none";
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句