我似乎无法弄清楚这一点。点击按钮后,它会打开一个对话框,确认您是否要继续“转到此链接”(即google.com)。如果是,它应该引导您链接。但是,我无法找到解决方法。我有两个不同链接的按钮。
查看jsfiddle here
HTML:
<button class="open" onclick="window.open('http://google.com')">Google</button>
<button class="open" onclick="window.open('http://yahoo.com')">Yahoo</button>
<div class="unique">Are you sure you want to continue?</div>
JS:
$(function() {
$('.open').on("click", function(e) {
var link = this;
e.preventDefault();
$('.unique').dialog({
buttons: {
"Ok": function() {
window.location = link.href;
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
});
});
CSS:
.unique {display: none;}
但是,如果我使用以下(http://jsfiddle.net/mJwMu/) - 它工作正常。但是,我只能指向一个链接。事实并非如此 - 我希望能够指向多个链接。 (google.com/yahoo.com/msn.com/etc)
HTML:
<button class="open">Google</button>
<div class="unique">Are you sure you want to continue?</div>
JS:
$(function() {
$('.open').on("click", function(e) {
var link = this;
e.preventDefault();
$('.unique').dialog({
buttons: {
"Ok": function() {
window.open('http://google.com');
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
});
});
CSS:
.unique {display:none;}
感谢您的帮助!
答案 0 :(得分:0)
HTML
<button class="open" data-href="http://www.google.com">Google</button>
<button class="open" data-href="http://www.yahoo.com">Yahoo</button>
<div class="unique">Are you sure you want to continue?</div>
的jQuery
$(function () {
$('.open').on("click", function (e) {
var link = this;
e.preventDefault();
$('.unique').dialog({
buttons: {
"Ok": function () {
window.open($(link).attr("data-href"));
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
});