簡體   English   中英

JavaScript函數-不傳遞參數

[英]JavaScript function - Not passing parameter

我正在使用jQuery Terminal。 創建一個命名為命令websites 每當有人在websites鍵入命令時, this.echo命中。 它將顯示超鏈接文本Test 當我點擊它。 它調用函數Test()並發出警報。

websites: function() {
    this.echo('<a target="_blank" href="" onclick="Test()">Test</a>', {raw:true});
},

測試功能:

function test(){
    alert('Success');
}

但是問題是,我想將URL作為參數傳遞給Test()函數。 並顯示在警報框中。

我已經嘗試過這種方式。

websites: function() {
    this.echo('<a target="_blank" href="" onclick="Test(http://www.google.com)">Test</a>', {raw:true});
},

參數測試功能:

function test(url){
    alert(url);
}

但是它永遠不會進入Test()函數。

我知道,這是語法錯誤。 但是到目前為止還沒有弄清楚。

您可以將它作為字符串傳遞

 function Test(x){ alert(x); } 
 <a target="_blank" href="" onclick="Test('http://www.google.com')">Test</a> 

暫無
暫無

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

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