[英]Jquery .span refresh onclick
Am I correct in thinking this should work? 我认为这应该正确吗?
I have this jquery: 我有这个jQuery的:
<script>
$(function() {
$(".wpsc_buy_button").click(function(evt) {
$(".counter").load("index.php")
evt.preventDefault();
})
})
</script>
This .span: 该.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>
And this button: 这个按钮:
<input type="submit" value="Add To Cart" name="Buy" class="wpsc_buy_button" id="product_16_submit_button"/>
You can change the code to work this way: 您可以更改代码以这种方式工作:
<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>
UPDATED 更新
You're doing it the hard way. 您正在用困难的方式做。 Here is the way you should do it: Locate the file http://tobyclothing.com/wp-content/plugins/wp-e-commerce/wpsc-core/js/wp-e-commerce.js?ver=3.8.7.6.2.494864 and find these lines: (line 248 - 257) 这是您应该执行的方法:找到文件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
});
your NEW_CODE will be: 您的NEW_CODE将是:
var current = parseInt($.trim($(".counter").text()));
$(".counter").text(current+1);
which will then result in: 然后将导致:
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);
});
UPDATE 2 更新2
If the user enters any number of quatity 如果用户输入任意数量的数量
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.