我有退出页面的PHP代码,但如果我点击导航框退出,我需要首先弹出一个确认框...如果我想退出或者不...可以帮助我吗?请
代码:
<?php
include("connection.php");
// Delete certain session
unset($_SESSION['username']);
// Delete all session variables
// session_destroy();
$uid = $_POST['uid'];
$stat="UPDATE users SET status='logout'";
mysql_query($stat);
// Jump to login page
header('Location: index.php');
?>
答案 0 :(得分:3)
也许这就是你想要实现的目标?
var logout = confirm("Are you sure to logout?");
if(logout){
location.href = "pathtologout.php";
}
答案 1 :(得分:2)
最简单:
<a href="logout.php" onclick="return confirm('Are you sure to logout?');">Logout</a>
答案 2 :(得分:1)
如果您只需要一个简单的确认,就可以这样做
$('#logout').click(function(){
var reallyLogout=confirm("Do you really want to log out?");
if(reallyLogout){
location.href="path/to/logout/file.php";
}
});
如果你不能使用jQuery(!),你可以使用纯Javascript来附加事件处理程序
function logout(){
var reallyLogout=confirm("Do you really want to log out?");
if(reallyLogout){
location.href="path/to/logout/file.php";
}
}
var el = document.getElementById("logout");
if (el.addEventListener) {
el.addEventListener("click", logoutfunction, false);
} else {
el.attachEvent('onclick', logoutfunction);
}