任何人都可以告诉我为什么这种方法在这里不起作用。('alphanumeric:true') 这是我的代码
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
fname: {
required: true,
alphanumeric:true, //I’m not sure about this if this is wrong please tell me
},
},
messages: {
fname: "Please enter your first name",
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});
HTML
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jQuery.validate.min.js"></script>
<script type="text/javascript" src="final.js"></script>
<script type="text/javascript" src="additional-methods.js"></script>
</head>
<body>
<form id="myform">
<input type="text" name="fname" /> <br/>
<input type="text" name="field2" /> <br/>
<input type="submit" />
</form>
</body>
</html>
答案 0 :(得分:2)
这可能不是您唯一的问题,但我可以告诉您,这在旧版本的IE中不起作用。
虽然它是完全有效的语法,但根据JS标准,当你在数组的最后一个元素之后留下尾随逗号时,IE不喜欢它。
我在您的代码中注明了这些问题,下面是:
$('#myform').validate({ // initialize the plugin
rules: {
fname: {
required: true,
alphanumeric:true, //trailing comma
}, //trailing comma
},
messages: {
fname: "Please enter your first name", //trailing comma
},
submitHandler: function (form) {
alert('valid form submitted');
return false;
}
});