我试图在单击按钮时打开一个对话框,打开的对话框包含一个登录表单,包括用户名和密码以及登录按钮。这是我打开对话框的 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 插件: