簡體   English   中英

如何使用jQuery調用已定義的變量?

[英]How do I call a defined variable with jQuery?

我有點卡住了。

我定義了三個變量:

var part1 = "<form><input type='button' value='Open Window' onclick='window.open('http://jsfiddle.net/
";
var part2="5Xket,"
var part3 = "'toolbar=no',menubar='no')></form>";

我的目的是在單擊按鈕時合並這些變量以創建工作鏈接。

這是我嘗試連接變量的值。

var mytest_2=part1+part2+part3;
alert (mytest_2);

通過單擊按鈕,應顯示mytest2中的按鈕。 單擊該按鈕,應該打開一個新窗口,其URL為http://jsfiddle.net/5Xket/

$('#searchbutton').click(function() {
$("<td class='testclass'><input id='an_id' type='text'></td>").show();
$(mytest_2).insertAfter('#an_id');

好吧,該按鈕應該出現,但不會打開一個窗口。 我的猜測是我在某處使用了錯誤的語法,因為警報發出了正確的變量順序。

有任何想法嗎? 謝謝。

我應該這樣:

var part1 = '<form><input id="button1" type="button" value="Open Window" /></form>';

$(part1).insertAfter('#an_id');

$('#button1').click(function(){
   window.open('http://jsfiddle.net/','5Xket','toolbar=no,menubar=no');
});

您的代碼存在的問題是雙引號/單引號未正確轉義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM