2013-05-08 90 views
-1

我是jquery的新手,我明天考试,我需要写几行代码。我需要在它和图像中创建一个带有产品的变种。我需要调用图像并将其添加到购物车。到目前为止,我有这个:jquery&添加项目到购物车

可以反馈意见!

 $(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

这是很难说这是怎么回事。一些HTML会有所帮助。 “validate_shoppingcart”是从哪里调用的? – 2013-05-08 09:18:51

+0

嗨大卫,没有任何HTML本身...考官正在寻找jquery代码...我不知道这是否有帮助 – user2304132 2013-05-08 10:38:55

+0

以及对于初学者来说,它没有太大的意义,有一个对象具有诸如'女士们“,那些应该是价值观,而不是钥匙。 – 2013-05-08 11:20:16

回答

0
var products = { 
    shoes: [ 
     {category: 'ladies', model: 'High Heels', qty: 10}, 
     {category: 'mens', model: 'Runners', qty: 5}, 
     {category: 'children', model: 'Slippers', qty: 6}, 
    ] 
} 

这样的事情会更有意义