• jquery 验证插件 示例


    <!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 >
    <style type="text/css">
    form.cmxform label.error, label.error { color: red; font-style: italic; } 
    </style>
    </head>
      <meta http-equiv="content-type" content="text/html" charset="utf-8"/>
      <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
      <script type="text/javascript" src="js/jquery.validate.js"></script>
      <script type="text/javascript" >
    $.validator.setDefaults({
    submitHandler: function() {
    alert("已经提交!");
    }
    });
    $().ready(function() {
    $("#commentForm").validate({
    rules: {
    name: {
    required:true,
    minlength:2
    },
    email: {
    required: true,
    email: true
    }
    },
    messages: {
    name: {
    required:"姓名必填",
    minlength:"至少2个字符"
    },
    email:"请输入一个邮件地址"
    });
    });
    </script>
    <body>
    <form class="cmxform" id="commentForm" method="get" action="">
    <legend>请输入你的姓名,电子邮件和网址,以及你的评论</legend>
    <label for="cname">姓名(必填,并2个字符)</label>
    <input id="cname" name="name" />
    <label for="cemail">电子邮件 (必填)</label>
    <input id="email" name="email" />
    <label for="curl">网址 (可选)</label>
    <input id="curl" name="url" value="" />
    <label for="ccomment">你的评论 (必填)</label>
    <textarea id="ccomment" name="comment" ></textarea>
    <input class="submit" type="submit" value="提交"/>
     
    </form>
    </body>
    </html>
     
     
    例 2:
     
    html 文件:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html" charset="utf-8"/>
    <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
      <script type="text/javascript" src="js/jquery.validate.js"></script>
      <script type="text/javascript" src="js/rules.js"></script>
    <script type="text/javascript">
    $(function(){
    validateform(); 
     
    })
     
    </script>
    </head>
    <body>
     
        <form id="myform" name="myform"  action="" method="get">  
        <table>
        <tr>
        <td><input type="text"  name="name"  /></td>
        </tr>
     
    <input type="text" name="email"  />
    <input class="submit" type="submit" value="提交" />
    </table>
    </form>
    </body>
    </html>
     
     
    js文件:
     
    function validateform()
    {
    $("#myform").validate({
    rules: {
    name: {
    required:true,
    minlength:2
    },
    email: {
    required: true,
    email: true
    }
    },
    messages: {
    name: {
    required:"姓名必填",
    minlength:"至少2个字符"
    },
    email:"请输入一个邮件地址"
    }
    });
    };
  • 相关阅读:
    基础数据结构总结
    图论总结
    【bzoj1614】[Usaco2007 Jan]Telephone Lines架设电话线
    【bzoj1015】星球大战starwar
    NOIP2012摆花
    最勇敢的机器人
    【bzoj1056】排名系统
    图的第k短路
    【bzoj1455】罗马游戏
    ti
  • 原文地址:https://www.cnblogs.com/soofly/p/3460838.html
Copyright © 2020-2023  润新知