涉及下拉菜单的jquery问题
这是我的情况,我正在使用 zen-cart 进行电子商务网站。
在产品详细信息页面中,产品属性如颜色和尺寸都在下拉菜单中。
要求是,当购物者单击“添加到购物车”而不选择属性时,会出现一条警告,提示选择颜色,这也适用于尺寸。
我的问题是,当我单击“添加到购物车”时,关闭框并单击“添加到购物车”而不选择属性后,会出现警告框,但没有任何反应。
这是 jQuery 编码
//#attrib-Size is the id for Size attribute
//#attrib-Color is the id for Color attribute
$("#attrib-Size").change(function(){
$("#for_alert").val(1);
});
$("#attrib-Color").change(function(){
$("#for_alert").val(1);
});
/*Add to cart */
$(".des_buynow_addcart").click(function(){
if($("#for_alert").val() == 1){
$("#for_alert").val(0);
if($("#attrib-Size").val() == 0){
alert ("PLEASE SELECT SIZE");
return false;
}
else if($("#attrib-Color").val() == 0){
alert ("PLEASE SELECT COLOR");
return false;
}
else{
这是 HTML 编码
<input class="des_buynow_addcart" type="image" src="includes/templates/********/buttons/english/addto-cart.png" alt="Add to Cart" title=" Add to Cart "/><br/>
<input type="hidden" value="1" name="for_alert" id="for_alert"/>
Here is my situation I'm using zen-cart for e-comm site.
In product details page there are products attributed like color and size both are in drop down menu.
The requirement was when a shopper clicks "add to cart" with out selecting the attributes a alert saying select color this goes for the size also.
My problem when I click "add to cart" the alert box appears after I close the box and click "add to cart" without selecting the attributes nothing happens.
This is jQuery coding
//#attrib-Size is the id for Size attribute
//#attrib-Color is the id for Color attribute
$("#attrib-Size").change(function(){
$("#for_alert").val(1);
});
$("#attrib-Color").change(function(){
$("#for_alert").val(1);
});
/*Add to cart */
$(".des_buynow_addcart").click(function(){
if($("#for_alert").val() == 1){
$("#for_alert").val(0);
if($("#attrib-Size").val() == 0){
alert ("PLEASE SELECT SIZE");
return false;
}
else if($("#attrib-Color").val() == 0){
alert ("PLEASE SELECT COLOR");
return false;
}
else{
This is HTML coding
<input class="des_buynow_addcart" type="image" src="includes/templates/********/buttons/english/addto-cart.png" alt="Add to Cart" title=" Add to Cart "/><br/>
<input type="hidden" value="1" name="for_alert" id="for_alert"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就是这一部分:
如果该值为 1,则将其设置为 0。现在,如果您再次单击该按钮,该值将为 0,因此它将一起跳过 if 。
It's this part:
If the value is 1, you then set it to 0. Now if you click the button again, the value will be 0 so it's going to skip the if all together.