簡體   English   中英

jQuery .span刷新onclick

[英]Jquery .span refresh onclick

我認為這應該正確嗎?

我有這個jQuery的:

<script>
    $(function() {
      $(".wpsc_buy_button").click(function(evt) {
         $(".counter").load("index.php")
         evt.preventDefault();
      })
    })
</script>

該.span:

<span class="counter">              
    <?php 
        $i = 0;
        while(wpsc_have_cart_items()): wpsc_the_cart_item();
    ?>
    <?php $i += wpsc_cart_item_quantity();  ?>
    <?php endwhile; ?>
    <?php print $i ?>
</span>

這個按鈕:

<input type="submit" value="Add To Cart" name="Buy" class="wpsc_buy_button" id="product_16_submit_button"/>

您可以更改代碼以這種方式工作:

<script>
    $(function() {
      $(".wpsc_buy_button").click(function(evt) {
        $.get("index.php", function(){
            var current = parseInt($.trim($(".counter").text()));
            $(".counter").text(current+1);
        });
         evt.preventDefault();
      })
    })
</script>

更新

您正在用困難的方式做。 這是您應該執行的方法:找到文件http://tobyclothing.com/wp-content/plugins/wp-e-commerce/wpsc-core/js/wp-e-commerce.js?ver=3.8。 7.6.2.494864並找到以下行:(第248-257行)

            jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
                eval(returned_data);
                jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

                if(jQuery('#fancy_notification') != null) {
                    jQuery('#loading_animation').css("display", 'none');
                //jQuery('#fancy_notificationimage').css("display", 'none');
                }
   // add your NEW_CODE here
            });

您的NEW_CODE將是:

    var current = parseInt($.trim($(".counter").text()));
    $(".counter").text(current+1);

然后將導致:

        jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
            eval(returned_data);
            jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

            if(jQuery('#fancy_notification') != null) {
                jQuery('#loading_animation').css("display", 'none');
            //jQuery('#fancy_notificationimage').css("display", 'none');
            }
var current = parseInt($.trim($(".counter").text()));
$(".counter").text(current+1);
        });

更新2

如果用戶輸入任意數量的數量

var qty = parseInt(jQuery("input[name='wpsc_quantity_update']").val());
            jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
                eval(returned_data);
                jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

                if(jQuery('#fancy_notification') != null) {
                    jQuery('#loading_animation').css("display", 'none');
                //jQuery('#fancy_notificationimage').css("display", 'none');
                }
    var current = parseInt(jQuery.trim(jQuery(".counter").text()));
    jQuery(".counter").text(current+qty);
            });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM