包含的库
@Scripts.Render("~/Scripts/jquery-ui-1.11.4.min.js")
@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")
@Scripts.Render("~/Scripts/jquery.validate.js")
我的验证仅在单击按钮时激活Add
:
$('#form1').validate({
rules: {
PROGRAM: {
required: true,
maxlength:20
},
UNIT:"required",
IS_ACTIVE:"required"
},
messages: {
PROGRAM: {
required: "Program Code is required.",
maxlength: "Program code cannot be over 20 characters long"
},
UNIT: {
required: "Unit code is required. Please select one."
},
IS_ACTIVE:{
required:"Is it active?"
}
},
errorElement: 'div',
errorLabelContainer: 'validationErrDisplay'
});
$('#programUnitInquiry').validate().cancelSubmit = false;
上面的代码以及事件处理程序(包括用于Add
按钮的处理程序)都包含在$(document).ready()
.
在form1
,PROGRAM
是一个文本框,其余的是下拉列表。当我单击UNIT
下拉列表时,会引发运行时错误。错误来自/Scripts/jquery.validate.js
文件中的第 1234 行,版本 1.10.0:
if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
$.each({
focus: 'focusin',
blur: 'focusout'
}, function( original, fix ){
$.event.special[fix] = {
setup:function() {
this.addEventListener( original, handler, true );
},
teardown:function() {
this.removeEventListener( original, handler, true );
},
handler: function(e) {
var args = arguments;
args[0] = $.event.fix(e);
args[0].type = fix;
return $.event.handle.apply(this, args);
}
};
function handler(e) {
e = $.event.fix(e);
e.type = fix;
return $.event.handle.call(this, e); // <-- error
}
});
}
错误信息:
0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“调用”
UNIT
下拉列表呈现后的 HTML:
<select name="UNIT" id="UNIT" data-val-required="The Unit Code field is required." data-val="true">
<option value="">-- Select a Unit --</option>
<!-- bunch of options retrieved from database -->
</select>