JavaScript函数 - 不传递参数
问题描述:
我正在使用jQuery终端。创建了一个名为websites
的命令。每当有人输入命令websites
this.echo
命中。它会显示一个超链接文本Test
。当我点击它。它调用一个功能Test()
,并会发出警报。JavaScript函数 - 不传递参数
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>
+0
是的。它的工作正常与纯html。 我需要使用this.echo :) –
字符串不会了'this'在'websites'功能是功能? – TankorSmash
您需要将您的URL包装在引号中。 –