1

これが私の簡単なコードです

 function goto() {
        /* Some code to be executed */
        if (a == "1")
              location.href = "http://www.google.com";
        else
              location.href = "http://www.example.com";
    }

そして、ここにhtmlがあります

<a href="#" onclick="goto();">Hello</a>

これは、通常どおりクリックすると完全に正常に機能しますが、右クリックして新しいタブで開くと実行されません。

4

4 に答える 4

0

次のようにします。

 function changeDest(elem) {
        /* Some code to be executed */
        if (a == "1")
              elem.href = "http://www.google.com";
        else
              elem.href = "http://www.example.com";
    }

 <a href="#" onmousedown="changeDest(this);">Hello</a>
于 2013-10-28T12:35:20.000 に答える