Javascript jQuery用户登录弹出框
我有一个显示所有可用模块的模块列表(从数据库检索)。对于每个模块,都会有一个“订阅”按钮。我想实现的是,当用户在登录帐户之前单击“订阅”时,页面将弹出一个登录框,让用户登录。然而,如果他已经登录并单击“订阅”,则应将此模块添加到他在数据库中的记录中 module_list.phpJavascript jQuery用户登录弹出框,javascript,php,jquery,popup,Javascript,Php,Jquery,Popup,我有一个显示所有可用模块的模块列表(从数据库检索)。对于每个模块,都会有一个“订阅”按钮。我想实现的是,当用户在登录帐户之前单击“订阅”时,页面将弹出一个登录框,让用户登录。然而,如果他已经登录并单击“订阅”,则应将此模块添加到他在数据库中的记录中 module_list.php <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="
<!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>
在表单内部按下提交按钮时,默认事件是将表单提交到服务器。要防止默认事件,您可以尝试
$('#subscribe').click(function(e) {
e.preventDefault();//prevent form submission.
................... // your code
}
查看jquery对话框。听起来这正是你想要的。链接:
谢谢,但它不起作用。最初我实际使用了
$('#subscribe').click(function(e) {
e.preventDefault();//prevent form submission.
................... // your code
}