• 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:"请输入一个邮件地址"
    }
    });
    };
  • 相关阅读:
    各种图示的介绍及绘制(boxplot、stem)
    各种图示的介绍及绘制(boxplot、stem)
    Python Tricks(二十二)—— small tricks
    Python Tricks(二十二)—— small tricks
    matplotlib tricks(关闭坐标刻度、坐标轴不可见)
    matplotlib tricks(关闭坐标刻度、坐标轴不可见)
    图灵机(Turing Machine)
    基于TCP/IP的Matlab Modbus与M340 PLC通讯
    hdu1195 Open the Lock (DFS)
    Java菜鸟学习笔记--数组篇(二):数组实例&args实例
  • 原文地址:https://www.cnblogs.com/soofly/p/3460838.html
Copyright © 2020-2023  润新知