2

这是我的代码:

var url = f.href.value;
ed.dom.setAttribs(e, {
    href : 'javascript:void(0)',
    onclick: 'doSomething(' + url + ')'
});

还有 doSomething 方法:

function doSomething(url) {
    windowMy = dhxWins.createWindow("externalLink", 10, 10, 630, 630);
    windowMy.setText("Title");
    windowMy.attachURL(url);
}

当 doSomething 被调用时,我得到错误:Uncaught SyntaxError: Unexpected token :, when url="http://somewebsite/site"。

我应该怎么办?如何在 JS 函数中将 url 作为参数传递?

4

1 回答 1

6

我认为您只需要在您的网址周围加上一些额外的引号:

var url = f.href.value;
ed.dom.setAttribs(e, {
    href : 'javascript:void(0)',
    onclick: 'doSomething("' + url + '")'
});

否则,函数会像这样结束:

doSomething(http://www.google.com);

代替:

doSomething("http://www.google.com");
于 2013-09-18T13:51:53.027 回答