0

私はこれを理解できないようです。ボタンをクリックすると、「このリンクに移動」(つまり google.com) を続行するかどうかを確認するダイアログが開きます。はいの場合は、リンクに移動する必要があります。しかし、私はそれを回避する方法を見つけることができません。リンクが異なる2つのボタンがあります。

ここでjsfiddleを表示

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/ )、正常に動作します。ただし、1 つのリンクにしか移動できません。そうではありません-複数のリンクに誘導できるようにしたいのです。(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 {表示: なし;}

あなたの助けに感謝します!

4

1 に答える 1

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");
                }
            }
        });
    });
});
于 2013-05-22T13:52:41.863 に答える