当前位置: 代码迷 >> ASP.NET >> |zyciis| jquery.validate 怎么动态添加和删除验证内容,多谢
  详细解决方案

|zyciis| jquery.validate 怎么动态添加和删除验证内容,多谢

热度:1310   发布时间:2013-02-25 00:00:00.0
|zyciis| jquery.validate 如何动态添加和删除验证内容,谢谢
HTML code
<!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 src="../lib/jquery.js" type="text/javascript"></script>    <script src="../jquery.validate.js" type="text/javascript"></script>    <script type="text/javascript">        $(function()        {            $("#user").validate(            {                rules:                {                    name: { required: true, minlength: 5 },                    pass: { required: true }                }            });        });    </script></head><body>    <form id="user" method="post">    <label>        Name</label>    <input name="name" type="text" value="" />    <label>        Pass</label>    <input name="pass" type="text" value="" />    <label>        Email</label>    <input name="email" type="text" value="" />    <input type="submit" value="submit" />    </form></body></html>

如上面已经对name pass 进行了不为空的验证了
那我现在如何写一条javascript将email动态的添加验证不为空呢?

谢谢

------解决方案--------------------------------------------------------
在初始化时设定:
HTML code
  <script type="text/javascript">        $(function()        {            $("#user").validate(            {                rules:                {                    name: { required: true, minlength: 5 },                    pass: { required: true },                    email:{ required: true, email: true }                }            });        });    </script>
------解决方案--------------------------------------------------------
探讨
在初始化时设定:
HTML code<scripttype="text/javascript">
$(function()
{
$("#user").validate(
{
rules:
{
name: { required:true, minlength:5 },
pass: { required:true },
email:{ required:true, email:true }
}
});
});</script>

动态设定
HTML code$("#email").rules("add", { required: true, email: true });

------解决方案--------------------------------------------------------
up
------解决方案--------------------------------------------------------
1楼强悍
------解决方案--------------------------------------------------------
学习了。
  相关解决方案