首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

ligerui 弹出层用validate印证,为什么不起作用

2013-06-25 
ligerui弹出层用validate验证,为什么不起作用!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional

ligerui 弹出层用validate验证,为什么不起作用

<!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="App/Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="App/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
    <script src="App/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script src="App/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
</head>
<body>
<script>
    function formChk() {

        $("#mainform").validate({
            errorPlacement: function (error, element) {
                error.insertAfter(element);
            },

            rules: { Name: { required: true }, Pwd: { required: true, digits: true} },
            messages: { Name: { required: "用户名" }, Pwd: { required: "密码", digits: "数字"} }, debug: true,
            invalidHandler: function () {
                alert('失败');
            },
            submitHandler: function () {
                alert("成功");
                            }

        });
    }
    function ShowWindow() {       
        $("#mainform").ligerForm({
            inputwidth: 150,
            fields: [{ name: 'Id', type: 'hidden' },
         { display: '姓名', name: 'Name', width: 150, type: 'text' },
         { display: '密码', name: 'Pwd', width: 150, type: 'text'}
         ]
        });
        detailWin = $.ligerDialog.open({
            target: $("#detail"),
            width: 595, height: 460, top: 80, title: "标题", //240
            buttons: [


                    { text: '保存', onclick: function () { formChk();} },
                    { text: '取消', onclick: function () { detailWin.hide(); } }
                    ]
        });
    }
</script>
<div id="detail" ><a href="#" onclick="ShowWindow()">jkjkjkj</a><form id="mainform" method="post"></form></div>
</body>
</html>


为什么我这样弄了,验证不通过也不提示信息,既不提示"成功",也不提示"失败" HTML
[解决办法]
他那个按钮是在表单外的,不是在表单内,并且div模拟,触发验证事件需要点击type=submit按钮才行

<!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="App/Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="App/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
    <script src="App/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script src="App/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
</head>
<body>
<script>
    function formChk() {
 
        $("#mainform").validate({
            errorPlacement: function (error, element) {
                error.insertAfter(element);
            },
 
            rules: { Name: { required: true }, Pwd: { required: true, digits: true} },
            messages: { Name: { required: "用户名" }, Pwd: { required: "密码", digits: "数字"} }, debug: true,
            invalidHandler: function () {
                alert('失败');
            },
            submitHandler: function () {
                alert("成功");
                            }


 
        });
    }
    function ShowWindow() {       
        $("#mainform").ligerForm({
            inputwidth: 150,
            fields: [{ name: 'Id', type: 'hidden' },
         { display: '姓名', name: 'Name', width: 150, type: 'text' },
         { display: '密码', name: 'Pwd', width: 150, type: 'text'}
         ]
        });
formChk();//注册验证事件
        detailWin = $.ligerDialog.open({
            target: $("#detail"),
            width: 595, height: 460, top: 80, title: "标题", //240
            buttons: [
                    //{ text: '保存', onclick: function () { formChk();} },//这个不需要了,点击不会触发验证事件
                    { text: '取消', onclick: function () { detailWin.hide(); } }
                    ]
        });
    }
</script>
<div id="detail" ><a href="#" onclick="ShowWindow()">jkjkjkj</a><form id="mainform" method="post"><input type="submit" value="提交"/></form></div>
</body>
</html>

热点排行