LigerUI 传统表单验证

<!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>
    <link href="ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" /> 
    <script src="jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="ligerUI/js/ligerui.all.js" type="text/javascript"></script>
       
    <script src="jquery-validation/jquery.validate.min.js"></script>
    <script src="jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="jquery-validation/messages_cn.js" type="text/javascript"></script>
       
    <style type="text/css">
        textarea{
            resize: none;
        }
           
    </style>
       
     <style type="text/css">
           body{ font-size:12px;}
        .l-table-edit {}
        .l-table-edit-td{ padding:4px;}
        .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
        .l-verify-tip{ left:230px; top:120px;}
    </style>
    
    
    <script type="text/javascript">
        var eee;
        $(function ()
        {
            $.validator.addMethod(
                    "notnull",
                    function (value, element, regexp)
                    {
                        if (!value) return true;
                        return !$(element).hasClass("l-text-field-null");
                    },
                    "不能为空"
            );
            $.metadata.setType("attr", "validate");
            var v = $("form").validate({
                //调试状态,不会提交数据的
                debug: true,
                errorPlacement: function (lable, element)
                {
                    if (element.hasClass("l-textarea"))
                    {
                        element.addClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field"))
                    {
                        element.parent().addClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                    $(element).attr("title", lable.html()).ligerTip();
                },
                success: function (lable)
                {
                    var element = $("#" + lable.attr("for"));
                    if (element.hasClass("l-textarea"))
                    {
                        element.removeClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field"))
                    {
                        element.parent().removeClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                },
                submitHandler: function ()
                {
                    $.ligerDialog.success("Submitted!");
                }
            });
            $("form").ligerForm();
            $(".l-button-test").click(function ()
            {
                //alert(v.element($("#txtName")));
            });
        }); 
    </script>
    
</head>
<body>
    <form name="form1" method="post"  id="form1">
        <table cellpadding="0" cellspacing="0" class="l-table-edit" >
            <tr>
                <td align="right" class="l-table-edit-td">名字:</td>
                <td align="left" class="l-table-edit-td" style="width:160px" ><input name="txtName" type="text" id="txtName" ltype="text" validate="{required:true,minlength:3,maxlength:10,notnull:true}" nullText="不能为空!"/></td>
                <td align="left"></td>
            </tr>
              
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">性别:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                    <input id="rbtnl_0" type="radio" name="rbtnl" value="1" checked="checked" /><label for="rbtnl_0">男</label> <input id="rbtnl_1" type="radio" name="rbtnl" value="2" /><label for="rbtnl_1">女</label>
                </td><td align="left"></td>
            </tr>  
             <tr>
                <td align="right" class="l-table-edit-td">Email:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="txtEmail" type="text" id="txtEmail" ltype="text" validate="{required:true,email:true}" /></td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">爱好:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                     <input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1$0" checked="checked" /><label for="CheckBoxList1_0">篮球</label><br /><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1$1" /><label for="CheckBoxList1_1">网球</label> <br /><input id="CheckBox1" type="checkbox" name="CheckBoxList1$1" /><label for="CheckBoxList1_1">足球</label>     
                </td><td align="left"></td>
            </tr> 
                    
            <tr>
                <td align="right" class="l-table-edit-td">入职日期:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                    <input name="txtDate" type="text" id="txtDate" ltype="date" validate="{required:true}" />
                </td><td align="left"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td">年龄:</td>
                <td align="left" class="l-table-edit-td" style="width:160px">
                    <input name="txtAge" type="text" id="txtAge" ltype='spinner' ligerui="{type:'int'}" value="20" class="required" validate="{digits:true,min:1,max:100}" />
                </td><td align="left"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td">部门:</td>
                <td align="left" class="l-table-edit-td" style="width:180px">
                <select name="ddlDepart" id="ddlDepart" ltype="select">
                    <option value="1">主席</option>
                    <option value="2">研发中心</option>
                    <option value="3">销售部</option>
                    <option value="4">市场部</option>
                    <option value="5">顾问组</option>
                </select>
                                </td><td align="left"></td>
                            </tr>
                            <tr>
                                <td align="right" class="l-table-edit-td">地址:</td>
                                <td align="left" class="l-table-edit-td" colspan="2">
                                <textarea cols="100" rows="4" class="l-textarea" id="address" style="width:400px" validate="{required:true}" ></textarea>
                                </td> <td align="left"></td>
                            </tr>
                        </table>
                 <br />
                <input type="submit" value="提交" id="Button1" class="l-button l-button-submit" />
                <input type="button" value="测试" class="l-button l-button-test"/>
    </form>
</body>
</html>


知识共享许可协议
《LigerUI 传统表单验证》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     162.87ms