How to use jQueryValidation without using name attributes
I'm using jQueryValidation and I would like to validate my form without needing to use name
attributes.
If the form elements don't have the name
attribute on开发者_开发知识库ly the first element is validated.
<!DOCTYPE html>
<html>
<head>
<title>jQuery Validation Demo</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.validate.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#loginButton').click(function(){
$('form').validate();
});
});
</script>
</head>
<body>
<form action="#" id="loginForm">
<input type="text" id="userText" class="required" placeholder="User" />
<input type="password" id="passwordText" class="required" placeholder="Password" />
<input type="submit" id="loginButton" value="Login" />
</form>
</body>
</html>
Thanks.
Try like this.
$("#loginForm").validate({
rules: {
userText:"required"
}
});
You have to use name
attribute in order to use class="required"
精彩评论