【发布时间】:2016-10-10 11:53:13
【问题描述】:
我想显示一个带有两个按钮是和否的确认框,当用户按下是时,将显示索引页面,当用户按下否时,此重定向到另一个页面。这确认 msgbox 仅在第一次打开网站时显示一次,而不是在每次重新加载页面时显示。谢谢
【问题讨论】:
标签: javascript php session alert confirm
我想显示一个带有两个按钮是和否的确认框,当用户按下是时,将显示索引页面,当用户按下否时,此重定向到另一个页面。这确认 msgbox 仅在第一次打开网站时显示一次,而不是在每次重新加载页面时显示。谢谢
【问题讨论】:
标签: javascript php session alert confirm
你可以试试这个代码
<script>
var confirm = confirm("sample message?");
if(confirm) {
// index page
window.location.url = ""; // your url index page
} else {
// other page
window.location.url = ""; // your url other page
}
</script>
【讨论】:
您必须在 javascript 中完成所有工作。 您可以使用的 Javascript 函数。 另外,您需要在浏览器中设置 cookie 并检查是否设置了 cookie。
function myFunction() {
var x;
if (confirm("Press a button!") == true) {
x = "You pressed OK!";
} else {
x = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = x;
}
希望这会有所帮助。
【讨论】:
function myFunction() {
var txt;
var r = confirm("Press a button!");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = txt;
}
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
【讨论】:
<html>
<head>
<title>Are you sure?</title>
<script>
function areYouSure() {
var res = confirm("Are you sure?");
return res; //true or false
}
</script>
</head>
<body>
<form method="POST" action="action_page.php">
<!--
...
-->
<input type="submit" onclick="return areYouSure()"/>
</form>
</body>
</html>
【讨论】: