[英]Google Sign-in: how to avoid popup dialog if user is already signed in by using listeners?
[英]jQuery User Sign-In Popup Box
我有一个模块列表,其中显示了所有可用的模块(从数据库中检索)。 对于每个模块,都会有一个“订阅”按钮。 我要实现的是,当用户在登录帐户之前单击“订阅”时,页面将弹出一个登录框,并让用户登录。而如果他已经登录并单击“订阅”,则该模块应该被添加到他在数据库中的记录。
module_list.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="css/default.css" rel="stylesheet" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="js/default.js"></script>
</head>
<body>
<?php
/* this part of code checks whether user has signed in. If he has, $_POST['userid'] will contain something, and checkuser will have value 1 (since userid is unique) */
$user = mysql_query("SELECT * FROM users WHERE userid = '".$POST['userid']."'");
$checkuser = mysql_num_rows($user);
if ($checkuser != 1) // if checkuser is not 1 (user hasnt signed in), pop up sign in box
{
?>
<div class="popup">
<a href="#" class="close">CLOSE</a>
<form>
<p><span class="title">Username</span> <input name="" type="text" /></p>
<p><span class="title">Password</span> <input name="" type="password" /></p>
<p><input name="" type="button" value="Login" /></p>
</form>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<?php
}
$sql = mysql_query("SELECT * FROM module");
while ($result = mysql_fetch_array($sql))
{
echo '<div id="middle">';
echo '<div id="title_prof"><a href="module.php?module='.$result['code'].'">'.$result['code'].' '.$result['name'].'</a><br />';
$profid = mysql_query("SELECT * FROM teach WHERE modulecode = '".$result['code']."'");
$profidresult = mysql_fetch_array($profid);
$checkprofid = mysql_num_rows($profid);
if ($checkprofid == 1)
{
$prof = mysql_query("SELECT * FROM prof WHERE profid = '".$profidresult['profid']."'");
$profresult = mysql_fetch_array($prof);
echo '<i> by '.$profresult['name'].'</i></div>';
echo '<div id="date_button"> created on: '.substr($result['date'], 0, 10);
echo '<br /><input type="submit" id="subscribe" value="Subscribe" /></div>';
}
echo '</div>';
echo '<hr>';
}
?>
</form>
</div>
</div>
这是触发弹出窗口所需的jQuery: default.js
$(document).ready(function () {
$('#subscribe').click(function() {
$("body").append('<div class="overlay"></div>');
$(".popup").show();
$(".close").click(function(e) {
$(".popup, .overlay").hide();
});
});
问题是,当我按下“订阅”按钮时,页面会刷新,但弹出窗口没有显示 。 我是jQuery的新手,我怀疑这个问题可能是由于我的js代码引起的。 任何人都可以在这里开灯吗?
在表单内部按下提交按钮时,默认事件是将表单提交到服务器。 为了防止发生默认事件,您可以尝试,
$('#subscribe').click(function(e) {
e.preventDefault();//prevent form submission.
................... // your code
}
查看jQuery对话框。 听起来这将完全满足您的要求。 链接: jQuery对话框
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.