Jquery 引导框如何在href链接上重定向
我是jquery和bootbox的新手,我想在确认的每个按钮警报中添加一个操作,所以如果选择的按钮是yes,那么我想在链接中重定向 例如Jquery 引导框如何在href链接上重定向,jquery,html,bootbox,Jquery,Html,Bootbox,我是jquery和bootbox的新手,我想在确认的每个按钮警报中添加一个操作,所以如果选择的按钮是yes,那么我想在链接中重定向 例如 <script type="text/javascript"> $(function() { bootbox.confirm({ message: "click yes to redirect google", buttons: { confirm: { label: 'Yes', className:
<script type="text/javascript">
$(function() {
bootbox.confirm({
message: "click yes to redirect google",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-success'
$(location).attr('href',"http://www.google.com/");
},
cancel: {
label: 'No',
className: 'btn-danger'
}
},
callback: function (result) {
console.log('This was logged in the callback: ' + result);
}
});
});
</script>
$(函数(){
bootbox.confirm({
消息:“单击“是”重定向google”,
按钮:{
确认:{
标签:'是',
类名:“btn成功”
$(位置).attr('href',”http://www.google.com/");
},
取消:{
标签:‘否’,
类名:“btn危险”
}
},
回调:函数(结果){
log('这是在回调中记录的:'+结果);
}
});
});
我使用了$(location.attr('href',”http://www.google.com/");代码>但它不起作用
感谢文档中的示例
所以你可以用这个
callback: function(result) {
if (result === true) {
location.href = 'http://www.google.com';
}
}
只需使用location.href=新值
。没有理由把它放在jQuery对象中。但是,您试图将其放入一个不正确的对象({}
)。bootbox可能有一些方法可以绑定单个按钮的回调,但不适用于location.href
callback: function(result) {
if (result === true) {
location.href = 'http://www.google.com';
}
}