可能重複:
AJAX Form Submission in jQuery Mobile禁用jQuery Mobile的形式按鈕動作
我有一個表格,我使用jQuery檢查和驗證的形式,因此,如果表格是空的,它不會提交表格,只會提醒「請填寫所有字段」。
function doShowError(eForm, sField, iInd, sError) {
var $Field = $("[name='" + sField + "']", eForm); // single (system) field
if(!$Field.length) // couple field
$Field = $("[name='" + sField + '[' + iInd + ']' + "']", eForm);
if(!$Field.length) // couple multi-select
$Field = $("[name='" + sField + '[' + iInd + '][]' + "']", eForm);
if(!$Field.length) // couple range (two fields)
$Field = $("[name='" + sField + '[' + iInd + '][0]' + "'],[name='" + sField + '[' + iInd + '][1]' + "']", eForm);
//alert(sField + ' ' + $Field.length);
$Field.parents('div:first').addClass('error');
$Field
.parents('div:first')
.addClass('error')
.children('img.warn')
.attr('float_info', sError)
//.show()
;
}
現在,問題是,每當我提交按鈕點擊,我得到只是一個短信說重定向到頁面(這應該是用戶面板):
undefined
如何禁用jQuery按鈕的默認功能?
編輯: 我的事件觸發和消息顯示,但我仍然重定向到在窗體的屬性action
定義的URL。
嗨!你在哪裏調用你的函數'doShowError'?你能提供更多的代碼嗎? – Littm