您可以更改代码以这种方式工作:
<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);
});
UPDATE 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);
});
是,将工作 - 我想补充一个';'的'load'线完整性......结束时,如果它不工作,什么是你期待它要做什么? – ManseUK 2012-03-28 14:34:02
我想在点击提交按钮时刷新span.counter。虽然似乎不适合我。 – bskool 2012-03-28 14:37:32
你的代码会覆盖'counter'的内容,看起来好像你向服务器发送任何东西..看看'get()'或'post()' – ManseUK 2012-03-28 14:38:32