我正在尝试添加 bootbox.js到测试页面。
目前,当我在触发 bootbox 的超链接中包含 href 标记时,无论我单击哪个确认按钮(取消或确定),都会触发 href。
如何将 href 标签包含到 bootbox js 代码中,仅当用户选择“确定”确认选项时才触发?我尝试了多次尝试,但无济于事。
这是带有 href 标签的超链接:
<a id="id_customized_details_duplicate" href="{% url customized_details_duplicate customized_detail.id %}">Duplicate</a>
这是我的书箱 js 代码:
$(document).ready(function(){
$('#id_customized_details_duplicate').on('click', function(){
bootbox.confirm("Are you sure?", function(result) {
if (result) {
//include the href duplication link here?;
//showProgressAnimation();
alert('OK SELECTED');
} else {
alert('CANCEL SELECTED');
}
});
});
});
最佳答案
尝试这种方式,防止 anchor 标记
的默认操作,并在bootbox
确认处理程序中使用相应的href
位置添加窗口重定向调用(当单击“确定”选项时)。
$(document).ready(function(){
$('#id_customized_details_duplicate').on('click', function(event){
event.preventDefault();
bootbox.confirm("Are you sure?", function(result) {
if (result) {
//include the href duplication link here?;
window.location = $(this).attr("href");
//showProgressAnimation();
alert('OK SELECTED');
} else {
alert('CANCEL SELECTED');
}
});
});
});
现场演示: http://jsfiddle.net/dreamweiver/9he30z4y/255/
快乐编码:)
关于javascript - bootbox 确认 - 选择“确定”时包括 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23539350/