2011-03-09 37 views
0

嗨我已經想出了一個小設計,但即時通訊有一個問題,它使用jQuery的onclick,如果用戶點擊產品它顯示產品信息在一個正確的痛苦butmy問題是它顯示每個產品的相同信息,即時編碼在本地主機上,所以不能鏈接任何人(抱歉)。這裏是我的代碼:鏈接到jquery中使用wordpress電子商務產品

<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/header/loader.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     $(".buynow").click(function() { 
      if($(".buynow").val() != 0) { 
       alert("The product has now been added to the Shopping cart, click checkout to pay for your items, or close this window to continue shopping."); 
      } 
     }); 

     // Put an animated GIF image insight of content 
     $("#col2").empty().html('<img src="<?php bloginfo('stylesheet_directory'); ?>/header/loading.gif" /> Loading...'); 

     // load index page when the page loads 
     $("#col2").load("<?php echo home_url('?page_id=2'); ?> .entry-content"); 
     $("#col1 li span").click(function(){ 
     // load home page on click 
      $("#col2").load("<?php echo home_url('?page_id=4&category=1&product_id='),wpsc_the_product_id(); ?> .entry-content"); 
     }); 
     //$("#about").click(function(){ 
     // load about page on click 
      //$("#response").load("about.html"); 
     //}); 
     //$("#contact").click(function(){ 
     // load contact form onclick 
      //$("#response").load("contact.html"); 
     //}); 

     $(".product").hover(
      function() { $(this).children(".price").show(); }, 
      function() { $(this).children(".price").hide(); } 
     ); 
    }); 
    </script> 

    <ul id="col1"> 

    <?php while (wpsc_have_products()) : wpsc_the_product(); ?> 

回答

0
echo home_url('?page_id=4&category=1&product_id='),wpsc_the_product_id(); 

也許這個逗號id='),wpsc應該是點?在JS

<ul id="col1"><li><span id="product-<?php echo wpsc_the_product_id() ?>">Product <?php echo wpsc_the_product_id() ?></span></li></ul> 

而且你應該做這樣的事情: 在HTML

$("#col1 li span").click(function(){ 
     var productId = $(this).attr("id");// gets the id of span which contains product id 
     productId = productId.split("-"); 
     productId = productId[1];// contains product id 
     // load home page on click 
      $("#col2").load("<?php echo home_url('?page_id=4&category=1&product_id=')?>"+ productId +" .entry-content"); 
     }); 

因爲你應該在循環聲明ID爲每一個產品,而不是在JS。如果你在js中聲明它,它將始終是相同的,硬編碼的。你可以看到,如果你在頁面加載時檢查你的js。它將始終調用第一個產品ID。

+0

與一些修補工作很好,謝謝:) – 2011-03-09 11:02:46

+0

你可以標記答案是正確的,謝謝:) – 2011-03-09 11:23:15

相關問題