【发布时间】:2013-01-09 10:41:52
【问题描述】:
当用户登录并在 html 表单上点击提交时,我正在使用 javascript 启动“shadowbox”jquery 灯箱窗口。
首先,我希望 jquery 窗口仅在提交成功时启动,而不是在提交失败时启动。 (即如果用户的电子邮件和密码正确) - 有没有办法做到这一点?
我遇到的另一个问题是,此时 jquery 窗口按预期弹出,但同时打开了第二个目标 _blank 窗口,因为我使用的是'this.target = 'formpopup';'
我试图使用'e.preventDefault();' 来阻止第二个窗口打开,这确实阻止了第二个窗口打开,但它也阻止了表单登录用户。无论如何我可以阻止第二个窗口完全在新的 _blank 窗口中打开而不删除 'this.target = 'formpopup';',因为这是打开 jquery 窗口所必需的。
谁能告诉我该怎么做,谢谢。
HTML 表格:
<form id="myform" form action="login.php" method="post" class="loginform">
Email
<input type="text" name="email" maxlength="30" />
Password
<input type="password" name="password" maxlength="30" />
<input type="image" src="../PTB1/assets/img/icons/loginarrow1.png" name="submit" class="loginbutton" value="Login" />
</form>
JAVASCRIPT:
<script>
$(document).ready(function() {
$('#myform').submit(function() {
Shadowbox.open({
content: '<iframe src="loginin.php" width="500" height="300" scrolling="no" style="overflow:hidden; border:none;"></iframe>',
player: "html",
height: 300,
width: 500
});
this.target = 'formpopup';
e.preventDefault();
});
});
</script>
【问题讨论】:
-
为什么需要
this.target = 'formpopup';?此外,您的e.preventDefault()行导致错误,因为没有e。检查您的错误控制台。
标签: javascript html login popup