例如,我有'firstname'字段的表单 . 我在这个字段中添加了两个规则(数字,必填) . 但是当我提交表格时,我只看到一个错误 . 如何查看错误列表(“此字段是必填项 . ”和“请输入有效数字 . ”)?
.error {
font: normal 10px arial;
padding: 3px;
margin: 3px;
background-color: #ffc;
border: 1px solid #c00;
}
body{font-size:x-large;background:#CCC;}
h1{margin-bottom:20px;}
form{padding:50px;}
$(document).ready(function(){
$("#form").validate({ rules: {
'firstname': {
number: true,
required: true,
},
}
});});
<form id='form' name='form' method='post' action=''><p>
<input type='text' name='firstname' id='firstname'/></p>
<input type='submit' name='Submit' value='Submit'/></p>
</form>
http://jsfiddle.net/4tcsjwah/398/
1 回答
非常确定这会有效,但要改变它以满足您的要求 .
访问这个JS小提琴:http://jsfiddle.net/JcFYr/1/