[英]jQuery submit won't submit form
我已經編寫了此腳本,但是在對話框上按“否”時,表單將不會提交。
這是腳本所在的頁面: 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
問題是您的手動提交代碼$('#quoteform').submit();
,當調用時,它將再次再次調用Submit事件處理程序,這將防止默認操作引起處理程序的遞歸調用。
相反,您可以嘗試調用dom元素的commit方法,該方法不會調用Submit事件處理程序。
$('#quoteform')[0].submit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.