我正在尝试将产品添加到购物篮中,但如果用户没有从某个选择输入中选择任何选项,我希望该选择出现在Bootstrap模式窗口中,该窗口显示用户点击“添加到篮子'没有选择任何选项。然后,如果用户选择了选项,则用户将继续。到目前为止的代码:
$('#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');
}
}
});
});
任何关于如何做到这一点的想法将不胜感激!谢谢!
答案 0 :(得分:2)
您可以通过在打开所选值的模式对话框之前进行检查来完成此操作,如果用户未选择一组值,则可以在模式对话框中显示这些下拉菜单,以便用户可以选择它们。用户单击保存按钮后,您将在客户端或服务器上或两者上进行验证。如果用户没有选择任何值,即使他打开了模态对话框,您也可以向他显示alert()
,并显示一条消息,他应该选择一个值,然后才能继续。
如果你真的无法解决它,我会为它提供代码。
<强>更新强>
我对此进行了更新,这里是代码,如果您需要不同的内容请告诉