【发布时间】:2012-10-14 16:37:39
【问题描述】:
我有一个表单,我使用 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()
;
}
现在的问题是,每当我点击提交按钮时,我都会被重定向到页面(应该是用户面板),其中只有一条文字:
未定义
如何禁用 jQuery 按钮默认的功能?
编辑:
我的事件触发并且消息显示,但我仍然被重定向到表单属性action 中定义的 URL。
【问题讨论】:
-
嗨!你在哪里调用你的函数
doShowError?能否提供更多代码?
标签: jquery jquery-mobile