2

だから私は、ボタンを使って誰かを次のような別のページにリンクできることを学びました。

$("#something").append("<br><center><input type='button' value='Go' onclick='location.href=\"http://www.google.com\"'></center>");

しかし、アドレスとして変数を使用したいとしましょう。その方法がわかりません。私がやろうとしていることは次のようなものです:

var url = "http://www.google.com";
$("#something").append("<br><center><input type='button' value='Go' onclick='location.href=url'></center>");

誰かが私のエラーを修正できますか?ありがとう

4

1 に答える 1

5

次のように、文字列内の url 変数を連結できます。

ライブデモ

$("#something").append("<br><center><input type='button' 
value='Go' onclick='location.href=" +url+ "'></center>");
于 2013-01-02T15:26:37.370 に答える