Javascript 在href之前执行click()函数中的方法

Javascript 在href之前执行click()函数中的方法,javascript,jquery,html,Javascript,Jquery,Html,我有一个按钮,上面有一个发送数据的href,在此之前,我想使用Bootbox.js HTML: 这只是执行href操作,因此不会使用Bootbox.js显示弹出窗口。是否有一种方法可以在关闭此项后立即执行函数和href 仅供参考:我认为您可以从HTML标记中删除超链接,只需保留按钮,然后执行以下操作:- $('.alert').click(function(){ bootbox.alert("Submitted!", function() { console.log("A

我有一个按钮,上面有一个发送数据的
href
,在此之前,我想使用
Bootbox.js

HTML:

这只是执行
href
操作,因此不会使用
Bootbox.js
显示弹出窗口。是否有一种方法可以在关闭此项后立即执行函数和href


仅供参考:

我认为您可以从HTML标记中删除超链接,只需保留按钮,然后执行以下操作:-

$('.alert').click(function(){
    bootbox.alert("Submitted!", function() {
        console.log("Alert Callback");
        window.location.href = '/submit?result=something';
    });
});

您可以使用
返回false

$('.alert').click(function(e){ // missed the . for the class selector
    bootbox.alert("Submitted!", function() {
        location.href = this.parentNode.href;
    });
    return false;
});

另一个建议是在按钮本身上使用
data-*
属性,而不是将其包装在锚点中:

<button class="alert btn btn-primary" data-href="submit?result=something" type="button">Submit</button>

在引导盒回调中显式触发
href
。请参阅
$('.alert').click(function(e){ // missed the . for the class selector
    bootbox.alert("Submitted!", function() {
        location.href = this.parentNode.href;
    });
    return false;
});
<button class="alert btn btn-primary" data-href="submit?result=something" type="button">Submit</button>
$('.alert').click(function(e){ // missed the . for the class selector
    bootbox.alert("Submitted!", function() {
        location.href = this.dataset['href'];
    });
});