繁体   English   中英

使用wordpress电子商务链接到jquery中的产品

[英]Linking to product in jquery using wordpress e-commerce

嗨,我想出了一个小设计,但即时通讯有一个问题,如果用户单击该产品,它会使用jquery onclick,它以正确的方式显示了产品信息,但是我的问题是,每个产品都显示了相同的信息,即时编码它在本地主机上,因此无法链接任何人(对不起)。 这是我的代码:

    <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(); ?>
echo home_url('?page_id=4&category=1&product_id='),wpsc_the_product_id();

也许这个逗号id='),wpsc应该是点?

另外,您应该执行以下操作:在html中:

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

在js中:

$("#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");
        });

因为您应该为每个产品(而不是js)在循环中声明id。 如果您在js中声明,它将始终相同,并进行硬编码。 您可以看到,如果您在页面加载时检查了js。 它将始终调用第一个产品ID。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM