我正在使用javascirpt和ajax来添加/更新/删除结帐篮子中的物品,
除IE8外,所有浏览器的外观和效果都很好。
在IE8上,当我添加/更新/删除项目到篮子时,我需要刷新篮子的窗口以获取值更改,是不是像其他浏览器那样动态地执行。它适用于IE9和IE10
这是我用于购物篮的功能
$('#add_to_basket').click(function(e) {
e.preventDefault();
var product_id = $('#add_to_basket').attr('rel');
var quentity = $('select[name="quantity"]').val();
var size = $('select[name="size"]').val();
var colour = $('select[name="colour"]').val();
var error = 0;
if (quentity == '') {
$('select[name="quantity"]').siblings('.selectBox-dropdown').eq(0).addClass('error');
error = 1;
}
if (size == '') {
$('select[name="size"]').siblings('.selectBox-dropdown').eq(1).addClass('error');
error = 1;
}
if (colour == '') {
$('select[name="colour"]').siblings('.selectBox-dropdown').eq(2).addClass('error');
error = 1;
}
if (error === 0) {
$.ajax({
url: site_url + '/basket/add',
type: 'POST',
data: {
quantity: quentity,
size: size,
colour: colour,
product_id: product_id
},
dataType: "json",
success: function(msg)
{
if (msg.success == true) {
$('#header_basket_list').html(msg.data);
$('#basket_count').text(msg.basket_count);
$('#proceed_to_checkout').show();
}
}
});
$("#dialog").dialog({
modal: true,
show: { effect: 'drop', direction: "up" },
hide: { effect: 'drop', direction: "up" },
open: function(){
setTimeout(function(event,ui){
$('#dialog').dialog("close");
}, 2000);
}
});
// window.setTimeout($("#dialog").dialog("close"),200);
}
});
$('.basket_drop').on('click', '.delete_btn', function() {
var selector = $(this);
$.ajax({
url: site_url + '/basket/delete_item',
type: 'POST',
data: {
key: $(selector).attr('rel')
},
dataType: "json",
success: function(msg)
{
if (msg.success == true) {
$(selector).parent().remove();
var basket_count = parseInt($('#basket_count').text()) - 1;
$('#basket_count').text(basket_count);
if (basket_count == 0) {
$('#proceed_to_checkout').hide();
}
}
}
});
});
$('.basket_drop').on('click', '.quantity_box .arrows', function() {
var selector = $(this);
var input = $(selector).parent().children('input');
var key = $(selector).parents('.basket_product').children('.delete_btn').attr('rel');
var basket_count;
if (input.length == 0)
return;
input = input.eq(0);
if ($(selector).hasClass('increase')) {
basket_count = input.val(parseInt(input.val()) + 1);
} else {
basket_count = input.val(parseInt(input.val()) > 1 ? parseInt(input.val()) - 1 : 1);
}
$.ajax({
url: site_url + '/basket/count_item',
type: 'POST',
data: {
key: key,
basket_count: basket_count.val()
},
dataType: "json",
success: function(msg)
{
if (msg.success == true) {
var price = $(selector).parents('.basket_product_info').children('.price').attr('rel');
var new_price = (price * parseFloat(basket_count.val()));
$(selector).parents('.basket_product_info').children('.price').children('spam').html(new_price.toFixed(2));
}
}
});
});
$('.basket_drop').on('keyup', '.quantity_box input[name="basket_count"]', function() {
var selector = $(this);
var input = $(selector).parent().children('input');
var key = $(selector).parents('.basket_product').children('.delete_btn').attr('rel');
var basket_count = $(selector).val();
$.ajax({
url: site_url + '/basket/count_item',
type: 'POST',
data: {
key: key,
basket_count: basket_count
},
dataType: "json",
success: function(msg)
{
if (msg.success == true) {
var price = $(selector).parents('.basket_product_info').children('.price').attr('rel');
var new_price = (price * parseFloat(basket_count));
$(selector).parents('.basket_product_info').children('.price').children('spam').html(new_price.toFixed(2));
}
}
});
});
非常感谢任何帮助,
非常感谢,