zoukankan      html  css  js  c++  java
  • 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:"请输入一个邮件地址"
    }
    });
    };
  • 相关阅读:
    PostgreSQL在Update时使用Substring函数截取字符串并且加上CASE WHEN THEN条件判断
    清理Visual Studio 2017的项目历史记录或手工修改Visual Studio 2017的注册表设置
    基于ABP模块组件与依赖注入组件的项目插件开发
    jenkins git can't work ERROR: Timeout after 10 minutes ERROR: Error fetching remote repo 'origin'
    SV randomize
    SV class
    SV coverage
    uvm设计分析——reg
    shell bash-shell
    scrapy的安装
  • 原文地址:https://www.cnblogs.com/soofly/p/3460838.html
Copyright © 2011-2022 走看看