我是jquery的新手,明天我要参加考试,我需要编写几行代码。我需要创建一个包含产品和图像的var。我需要调用图像并将其添加到购物车中。到目前为止,我有这个:
可以反馈意见!!!
$(document).ready(function() { // function contains everything, set to load when page is ready
var product; // 3 global variables rest of function can use
var source;
var shoppingcart;
var product = { //an array of products
shoes: [
{ladies: "High Heels", qty: 5},
{mens: "runners", qty: 10},
{childrens: "slippers", qty: 6},
]
};
var shoppingcart = ???????????
var source = $("#myImage").attr("src"); //images are stored here
$("#product").on("click", display_product);
var validate_shoppingcart = (function() {
shoppingcart.push($this)
});
OR SHOULD IT BE
var validate_shoppingcart = (function (e){ // I am Trying to call the image
$("#product").attr($this)
});
});
答案 0 :(得分:0)
var products = {
shoes: [
{category: 'ladies', model: 'High Heels', qty: 10},
{category: 'mens', model: 'Runners', qty: 5},
{category: 'children', model: 'Slippers', qty: 6},
]
}
这样的事情会更有意义