[英]Passing URL as parameter in JS function
This is my code: 这是我的代码:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething(' + url + ')'
});
And the doSomething method: 和doSomething方法:
function doSomething(url) {
windowMy = dhxWins.createWindow("externalLink", 10, 10, 630, 630);
windowMy.setText("Title");
windowMy.attachURL(url);
}
When doSomething is called, I get the error: Uncaught SyntaxError: Unexpected token :, when url="http://somewebsite/site". 调用doSomething时,出现错误:url =“ http:// somewebsite / site”时出现Uncaught SyntaxError:Unexpected token:。
What should I do? 我该怎么办? How can I pass url as parameter in JS function?
如何在JS函数中将url作为参数传递?
I think you just need some extra quotes around your url: 我认为您只需要在网址周围添加一些引号即可:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething("' + url + '")'
});
Otherwise, the function ends up like this: 否则,函数将如下所示结束:
doSomething(http://www.google.com);
Instead of: 代替:
doSomething("http://www.google.com");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.