繁体   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