1

「セクシー アラート ボックス」スクリプトを呼び出して、ユーザーが「同意する」および「キャンセル」オプションを使用して利用規約に同意するかどうかを尋ねるメッセージを表示するページへのリンクがあります。

たくさんのことを行っていますが、今は「同意する」オプションで新しいページに送信する必要があります。(「キャンセル」は、ユーザーに現在のページを返します。)

と関係がありdocument.location.hrefますか?

mootools フレームワークを使用しています。

セクシーアラートボックス 1.2 mootools & jQuery

コードは次のとおりです。

<a href="#" 
    onclick="Sexy.confirm('Do you agree to the terms and conditions?', {
        textBoxBtnOk: 'I Agree', // goes to www.newpage.com
        textBoxBtnCancel: 'Cancel' // return to current page    
    });">Link</a>
4

2 に答える 2

2

標準の組み込み JavaScriptconfirm関数は、押されたボタンに応じて true または false を返します (これは同期アクションです) が、このSexy.confirmプラグインはコールバック関数を介してその選択を返すもののように見えます (非同期アクションになります)。 )。

例えば、

function doConfirm() {
    Sexy.confirm('Do you agree to the terms and conditions?', {
        textBoxBtnOk: 'I Agree',
        textBoxBtnCancel: 'Cancel',
        onComplete: function(returnvalue) {
            // here is where you act, after user has made a choice...
            if (returnvalue) {
                //alert ("pressed OK");
                window.location.href = '/page1/';
            }
            else {
                //alert("pressed Cancel");
                window.location.href = '/page2/';
            }
        }
    });
    return false; // this is to cancel the native click event
}

そして、リンクタグをもう少し良くすることができます。

<a href="#" onclick="return doConfirm();">Link</a>

幸運を!

于 2009-09-03T04:26:36.997 に答える
1

Mootoolsの場合:

HTMLに使用

<a class="confirm" href="www.google.fr">Google Fr</a>
<a class="confirm" href="www.google.be">Google Be</a>

そしてJavaScript

window.addEvent('domready', function () {
    $$('a.confirm').each(function (el) {
        el.addEvent('click', function (e) {
            e.stop();
            Sexy.confirm('<h1>Etes-vous sur de vouloir suivre ce lien ?</h1>',{ 
                onComplete: function(returnvalue) {
                    if (returnvalue) {
                        window.location.href = el.get('href');
                    }
                },
                textBoxBtnOk: 'Oui',
                textBoxBtnCancel: 'Non'
            });
        });
    });
});
于 2011-02-11T02:42:43.647 に答える