0

我正在尝试将产品添加到购物篮,但如果用户没有从某个选择输入中选择任何选项,我希望该选择出现在引导模式窗口中,该窗口显示用户单击“添加到购物篮”时没有选择任何选项。然后,只有当他选择一个选项时,用户才会继续。到目前为止的代码:

$('#button-cart').bind('click', function() {
    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
        dataType: 'json',
        success: function(json) {
            $('.success, .warning, .attention, information, .error').remove();

            if (json['error']) {
                if (json['error']['option']) {
                    for (i in json['error']['option']) {

                         $('#deleteMessage').modal();
                         $('.modal-body').after('<span class="error">' + json['error']['option'][i] + '</span>');

                    }
                }
            } 

            if (json['success']) {
                $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

                $('.success').fadeIn('slow');

                $('#cart-total').html(json['totalProducts']);

                $('html, body').animate({ scrollTop: 0 }, 'slow'); 
            }   
        }
    });
});

任何关于如何做到这一点的想法将不胜感激!谢谢!

4

1 回答 1

2

您可以通过在打开模式对话框之前检查所选值来做到这一点,如果用户没有选择一组值,那么您可以在模式对话框中显示这些下拉菜单,以便用户可以选择它们。用户单击保存按钮后,您将在客户端或服务器上验证它,或在两者上验证它,您的选择。如果用户即使打开了模式对话框也没有选择任何值,您可以向他显示 alert()一条消息,告诉他他应该选择一个值,然后他才能继续。

如果你真的不能解决它,我会提供它的代码。

更新

我对此进行了更新,这是代码,如果您需要不同的东西,请告诉

http://jsfiddle.net/xrQzR/

于 2013-11-12T22:17:33.393 回答