当按下Delete user链接时,以下代码会弹出一个确认窗口:
<a href="delete_user.php?id=123" onclick="return confirm('Are you sure?');">Delete user</a>在这种情况下,当按下OK按钮时,将执行链接delete_user.php?id=123。当按下Cancel按钮时,不会发生任何事情。
我也想用Bootbox做同样的事情。
<a class="alert" href="list_users.php?id=123">Delete user</a>
<script src="bootbox.min.js"></script>
<script>
$(document).on("click", ".alert", function(e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function(result) {
if (result) {
// What to do here?
} else {
// What to do here?
}
});
});
</script>在if(result)和else语句下做什么?
发布于 2013-09-05 00:52:51
这对我很有效。抓取"click“href,当你有"result”时使用它。
<script>
$(document).on("click", ".alert", function(e) {
var link = $(this).attr("href"); // "get" the intended link in a var
e.preventDefault();
bootbox.confirm("Are you sure?", function(result) {
if (result) {
document.location.href = link; // if result, "set" the document location
}
});
});
</script>发布于 2015-08-20 01:25:12
这个很好用!
$(".alert").on("click", function (e) {
// Init
var self = $(this);
e.preventDefault();
// Show Message
bootbox.confirm("Are you sure?", function (result) {
if (result) {
self.off("click");
self.click();
}
});
});https://stackoverflow.com/questions/16987188
复制相似问题