关闭Bootstrap模式onclick

我正在使用Bootstrap模式供用户在将项目添加到购物车之前选择产品选项。 我之前在这种情况下使用它们没有任何问题,但是这个没有按预期关闭。

当用户点击“添加到购物车”按钮时,会发生一些事情,我认为问题就在那里。 首先,某些脚本会检查某些字段是否已正确完成。 一旦完成validation,用户就可以将项目添加到购物车中,此时会弹出另一个窗口,让他们查看购物车内容并选择继续购物车或继续停靠。

在脚本确认所有字段都已填写完毕后,单击“添加到购物车”按钮后,我希望关闭模态窗口。 目前,它只是坐在那里,如果用户选择继续他们离开的地方而另一个窗口关闭,它仍然存在。

模态的HTML:

 Buy This!   

SCRIPT检查字段:

  // Hides shipping info fieldset if ship to billing is checked $(function () { $("#ship_to_billing").change(function () { if ($(this).is(":checked")) $("#shipping_info").hide(); else $("#shipping_info").show(); }); }); // Validates address fields are filled out unless ship to billing is checked... function validateShipping() { if (!$("#ship_to_billing").is(":checked")) { var inputs = $("#shipping_info input"); var ready = true; inputs.each(function () { if ($(this).val() == '') { ready = false; return false; } }); if (!ready) { alert("Oops! Something's missing! Either choose 'Ship to My Billing Address' or all of the Recipient Name and Shipping Address fields must be completed. Thanks!"); return false; } } // Makes sure age verification is checked if (!$('#age_verification').is(':checked')) { alert("Please verify you are 21 years of age or older."); return false; } // Confirms province is allowed for wine shipping var states = ["AK", "AZ", "CA", "CO", "CT", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "LA", "ME", "MD", "MI", "MN", "MO", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OR", "SC", "TN", "TX", "VT", "VA", "WA", "WV", "WI", "WY", ""]; if ($.inArray($("#address_province").val().toUpperCase(), states) <0) { alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item."); return false; } return true; }  

使用javascript关闭模式框

 $('#product-options').modal('hide'); 

如果button标签位于包含模态的div元素内,您可以执行以下操作:

  

您可以隐藏模态并弹出窗口以查看validateShipping()函数本身的购物车。

 function validateShipping(){ ... ... $('#product-options').modal('hide'); //pop the window to select items } 

使用通用$().hide()方法关闭模态:

 $('#product-options').hide();