Oua*_*lid 7 javascript jquery twitter-bootstrap bootbox
按下删除用户链接时,以下代码会弹出确认窗口:
<a href="delete_user.php?id=123" onclick="return confirm('Are you sure?');">Delete user</a>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,当按下OK按钮时,将执行链接delete_user.php?id = 123.按下取消按钮时,不会发生任何事情.
我想用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>
Run Code Online (Sandbox Code Playgroud)
在if(result)和else语句下做什么?
小智 19
这对我有用.抓住"点击"href并在有"结果"时使用它.
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13273 次 |
| 最近记录: |