0

我试图在单击按钮时打开一个对话框,打开的对话框包含一个登录表单,包括用户名和密码以及登录按钮。这是我打开对话框的 html 代码:HTML 代码:

<body>
<div data-role="page">
 <div data-role="header" data-theme="e">
 <h3>PRAYERS APP</h3>
 </div>
<div data-role="content">
   <div class="center-wrapper">
      <a href="#login_box"  id="showdialog" data-transition="pop" data-rel="dialog" data-role="button" data-icon="plus" data-theme="e">USER LOGIN AREA</a>
   </div>

</div>
 </div>


<div data-role="dialog" id="login_box" class="login-popup" data-dismissible="false">

<a href="#" id="closeBtn" class="ui-btn-right" data-role="button" data-rel="back" data-icon="delete" data-iconpos="notext">close btn</a>  

 <div data-role="content">
    <div class="ui-body ui-body-b">
            <form name="login" id="formlogin" method="get" action="" accept-charset="utf-8">

                <div data-role="fieldcontain">
                    <label for="username">USER NAME:</label><br/>
                    <input type="text" name="username" id="usrname" placeholder="your name"/><br/>
                </div>

                <div data-role="fieldcontain">
                    <label for="password">PASSWORD:</label><br/>
                    <input type="password" name="password" id="usrpswd" placeholder="please enter your password"/><br/>
                </div>

                <fieldset class="ui-grid-a">
                 <div class="ui-block-a">
                 <a href="#" id="signinbtn" data-role="button" data-theme="b" data-icon="check" style="text-align:center; float:right;">SIGN  IN</a></div>
                </fieldset>

                </form>
                    </div>
                      </div>
                       </div>
<!--  -----login page   end------------------->                        
</body>

当我单击“用户登录区域按钮”时,另一个问题是在另一个页面上显示对话框,而我想在同一页面上打开一个对话框:应用淡入淡出的 JS 代码:

<head>
<script>
$(document).ready(function()
 {
<!-- ///////////////////////////////login dialog and its validation start//////////////////////////////////////////////////////////--> 

    var loginBox;
          $('#showdialog').click(function()
         {
            loginBox = $(this).attr('href'); 
            //Fade in the Popup and add close button
            $(loginBox).fadeIn(250);
            //Set the center alignment padding + border
            var popMargTop = ($(loginBox).height() + 24) / 2;
            var popMargLeft = ($(loginBox).width() + 24) / 2;

            $(loginBox).css({
                'margin-top': -popMargTop,
                'margin-left': -popMargLeft
                });
            $('body').append('<div id="mask"></div>');
            $('#mask').fadeIn(250);

            return false;
         });

        // When clicking on the close button  or the mask layer the popup closed
         $('#closeBtn, #mask').live('click',function()
          {
             $('#mask, .login-popup').fadeOut(250,function()
                {
                 $('#mask').remove(); 
                });
             return false;
          });
   });
</script>
</head>

现在在打开对话框的文本框上应用验证时遇到问题,因为我正在使用此代码但它不起作用:我在脚本标记中应用此代码

$('#login_box').dialog(
    {
    open: function(event,ui)
    {
    $('#formlogin').validate()
    {
    rules:
    {
    username:
        {required: true,
        minlength: 4
        },
        }
    password:
      {required: true,
      minlength: 8
      }
    },
     messages:
     {
     username: 
     {required:"pls enter user name",
     minlength: $.format("Keep typing, at least {0} characters required!"),
     }
    password:
     {
     required:"pls enter password",
     minlength: $.format("password should be atleast {0} characters")
    }

    }
    } 
    }
    });

此外,对话框的登录按钮不可点击,无法触发此功能:

  $('#signinbtn').on('click',function()
            {
                alert("eerer");
                doLogin();


            });   

我想要这种类型的验证是小提琴: formvalidation 我已经在我的项目中应用了所有 jquery 插件:

4

1 回答 1

0

.validate()是在表单上初始化插件的方法。将其上移一层,使其立即在您的 DOM 就绪处理程序中。

您的.validate()代码中还有很多语法错误。适当的缩进和格式将帮助您轻松查看它们...

$('#formlogin').validate() { // <-- should be .validate({
    rules: {
        username: {
            required: true,
            minlength: 4
        },
    } // <-- extra } puts password outside of rules
    password: {
        required: true,
        minlength: 8
    }
},
messages: {
    username: {
        required: "pls enter user name",
        minlength: $.format("Keep typing, at least {0} characters required!"), // <-- extra comma
    } // <-- missing a comma
    password: {
        required: "pls enter password",
        minlength: $.format("password should be atleast {0} characters")
    }

}
} // <-- should be a });

这个格式正确...

$(document).ready(function () {

    $('#formlogin').validate({
        rules: {
            username: {
                required: true,
                minlength: 4
            },
            password: {
                required: true,
                minlength: 8
            }
        },
        messages: {
            username: {
                required: "pls enter user name",
                minlength: $.format("Keep typing, at least {0} characters required!")
            },
            password: {
                required: "pls enter password",
                minlength: $.format("password should be atleast {0} characters")
            }
        }
    });

});

简单演示:http: //jsfiddle.net/qzdyk/

我为您的演示添加了一个submit按钮。form该插件将自动捕获并处理a和 a的click事件。<input type="submit" /><button>click</button>

于 2013-04-18T15:13:30.070 回答