jquery验证无法使用jquery验证插件 [英] Jquery validation is not working using jquery validation plugin
本文介绍了jquery验证无法使用jquery验证插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了一个使用jquery验证插件的简单验证,但是我无法实现它。当我单击提交按钮时没有更改,请在此帮助我
I tried a simple validation using jquery validation plugin but I was not able to achieve it.Nothing get's changed when i click the submit button, please help me on this
我已经提到了下面的代码,
I've mentioned the code below,
在此先感谢。
Thanks in advance.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js" />
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js" />
<script type="text/javascript">
$(document).ready(function () {
$('#btnSubmit').click(function () {
$('#logform').validate({
rules: {
txtUsr: {
required: true
},
txtPass: {
required: true
}
},
messages: {
txtUsr: {
required: 'Please enter username'
},
txtPass: {
required: 'Please enter password'
}
}
});
});
});
</script>
</head>
<body>
<div id='LoginDiv' style='width:400px;height:300px;background-color:green;'>
<form method="post" action="" id='logform'>
User Name : <input type="text" id='txtUsr' name='txtUsr' style='margin-top:12px'/>
<br/>
<br/>
Password : <input type="text" id='txtPass' name='txtPass' />
<br/>
<br/>
<input type="submit" id='btnSubmit' value='Submit' />
</form>
</div>
</body>
</html>
推荐答案
问题归因于脚本自闭标签。 / h2>
尝试一下:
http://jsfiddle.net/adiioo7/FFTkJ/
Problem is due to script self-closing tags.
Try this out:
http://jsfiddle.net/adiioo7/FFTkJ/
使用
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js"></script>
而不是
instead of
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js" />
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js" />
另请检查 为什么不能自动关闭脚本标记?
Also check this Why don't self-closing script tags work?
这篇关于jquery验证无法使用jquery验证插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文