我已经写了这个脚本,但是当'No‘按在对话框上时,表单将不会提交。
这是脚本所在的页面:http://www.absoluteglazing.co.uk/quotation?item=walkon
我肯定这是很简单的事情,但我想不出来。
$( document ).ready(function() { // Document ready function
$('#quoteform').submit(function(event) { // Submit form function
event.preventDefault(); // Stop form from submitting
// Variable declaration
var GetLength = $('#length').val(); // Length variable
var GetWidth = $('#width').val(); // Width variable
var GetLengthUnit = $('#length_unit').val(); // Length variable
var GetWidthUnit = $('#width_unit').val(); // Width variable
var GetNoPanes = $('input[name=nopanes]:checked').val(); // Number of panes variable
var GetLocation = $('#thelocation').val(); // Location variable
var GetAntislip = $('#antislip:checked').val(); // Antislip checked variable
var GetFirerated = $('#firerated:checked').val(); // Fire Rated checked variable
var GetSolarcontrol = $('#colarcontrol:checked').val(); // Solar Control checked variable
var GetLengthConverted
var GetWidthConverted
var GetPaneLength
var GetPaneWidth
// End of ariable declaration
if(GetLength < GetWidth) { // If length is less than width
$('#length').val(GetWidth); // Set length to width
$('#width').val(GetLength); // Set width to length
var GetLengthTemp = GetWidth;
var GetWidthTemp = GetLength;
GetLength = GetLengthTemp;
GetWidth = GetWidthTemp;
} // End if length is less than width
if(!$.isNumeric(GetLength) || !$.isNumeric(GetWidth)) { // Check to see if length and width are numeric
swal({
title: "Error!",
text: "Please enter a valid length and width",
type: "error",
confirmButtonColor: "#f36e21",
confirmButtonText: "OK" });
} else { // If length and width are valid then continue
if(GetLengthUnit == 'cm') { // cm to mm conversion
GetLengthConverted = GetLength * 10;
} else if(GetLengthUnit == 'm') { // m to mm conversion
GetLengthConverted = GetLength * 1000;
} else if(GetLengthUnit == 'inches') { //inches to mm conversion
GetLengthConverted = GetLength * 25.4;
} else if(GetLengthUnit == 'feet') { // feet to mm
GetLengthConverted = GetLength * 304.8;
} else { // if in mm then no conversion needed
GetLengthConverted = GetLength;
}
if(GetWidthUnit == 'cm') { // cm to mm conversion
GetWidthConverted = GetWidth * 10;
} else if(GetWidthUnit == 'm') { // m to mm conversion
GetWidthConverted = GetWidth * 1000;
} else if(GetWidthUnit == 'inches') { //inches to mm conversion
GetWidthConverted = GetWidth * 25.4;
} else if(GetWidthUnit == 'feet') { // feet to mm
GetWidthConverted = GetWidth * 304.8;
} else { // if in mm then no conversion needed
GetWidthConverted = GetWidth;
}
if(GetNoPanes == 1) { // If one pane
GetPaneLength = GetLengthConverted;
GetPaneWidth = GetWidthConverted;
} else if(GetNoPanes == 2) { // If two panes
GetPaneLength = GetLengthConverted / 2;
GetPaneWidth = GetWidthConverted;
} else if(GetNoPanes == 3) { // If three panes
GetPaneLength = GetLengthConverted / 3;
GetPaneWidth = GetWidthConverted;
} else if(GetNoPanes == 4) { // If four panes
GetPaneLength = GetLengthConverted / 2;
GetPaneWidth = GetWidthConverted / 2;
} else { // If five or more panes
GetPaneLength = 5000; // Use 5000 for error checking 5 panes or more
GetPaneWidth = 5000; // Use 5000 for error checking 5 panes or more
}
if(GetPaneLength > 2950 || GetPaneWidth > 2400) {
swal({
title: "Are you sure?",
text: "The size of glass panes in your quotation are quite large and will increase the cost. Would you like to split this into more panes of glass?",
type: "info",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: true,
closeOnCancel: false },
function(isConfirm){
if (isConfirm) {
// Nothing, just close dialog
} else {
alert('Just testing something is happening');
$('#quoteform').submit();
} });
}
} // End check to see if length and width are numeric
}); // End submit form function
}); // End document ready function发布于 2015-07-28 10:03:31
问题在于手动提交代码$('#quoteform').submit();,当调用该代码时,它将再次调用submit事件处理程序,这反过来将防止导致该处理程序递归调用的默认操作。
相反,您可以尝试调用dom元素的submit方法,该方法不会调用submit事件处理程序。
$('#quoteform')[0].submit();https://stackoverflow.com/questions/31673076
复制相似问题