我正在尝试使用与ajaxForm快速验证。问题是我不认为我在beforeSubmit的时候强迫spry验证是找到表单。我没有得到任何错误,似乎beforeSubmit没有触发因为它找不到表单,"form1"
$("#form1").ajaxForm({
url: "processPhoneEdit.php",
beforeSubmit: function(){
if (Spry) { // checks if Spry is used in your page
var r = Spry.Widget.Form.validate(form1); // validates the form
if (r)
alert("testing");
return (r);
}
},
success: alert("success"),
complete: alert("complete")
});
我不是一个很好的程序员,但这是我的解决方案:
// Submit button is clicked
$("#submitShipment").click(function ()
{
// Spry validation: if true
if (Spry.Widget.Form.validate(form1) == true)
{
// opens the Please Wait dialog
$('#dialogPleaseWait').dialog('open');
// disables the submit button
$('#submitShipment').button('disable');
// Posts form to callback page, serializes the form into a URL string and waits for a result (success / fail)
$.get("callbacks/insertShipment.asp", $("#form1").serialize(), insertCallback);
}
else // Spry validation: if false
{
// opens jQuery UI dialog to inform user Validation failed
$('#dialogDespatchValFail').dialog('open');
}
});
试试这个…
$("#form1").ajaxForm({
target:'#some_div',
url:'processPhoneEdit.php',
clearForm: 'true',
beforeSubmit: function(formData, jqForm, options){
if (Spry) { // checks if Spry is used in your page
r = Spry.Widget.Form.validate(jqForm[0]); // validates the form
if (!r) {
return r;
}
}
if(r) {
$('#submit').attr({
'disabled':'disabled',
'value':'Processing. Please Wait...'
});
}
},
success: function() {
$('#form1').hide();
}
});