简体   繁体   English

在javascript中传递url作为参数不会调用该函数

[英]passing url as parameter in javascript is not calling the function

<a href="javascript:void();" onclick="openWindow(2,1,4326,http://www.../images/icon_tree1.gif);">Edit Asset Info</a>

Function openWindow is not called and I am see the folowing error on console 函数openWindow没有被调用,我在控制台上看到了以下错误

Uncaught SyntaxError: Unexpected token : and Uncaught SyntaxError: Unexpected token :

Uncaught SyntaxError: Unexpected token )

This is the actual code I am using 这是我正在使用的实际代码

return "<a href='javascript:void();' onclick='openWindow(" 2 "," + 1 + "," + 4326 + "," + symbolurl + ");'>Edit Asset Info</a>";

URL地址是一个字符串,因此您应该用引号括起来:

... onclick="openWindow(2,1,4326,'http://www.../images/icon_tree1.gif');" ...

You need to pass a string to the onclick handler onclick="openWindow(1, 2, 3, 'http://...')" Some other comments: 你需要将一个字符串传递给onclick处理程序onclick="openWindow(1, 2, 3, 'http://...')"其他一些评论:
1, If your anchor doesn't actually take the user anywhere, consider not to use <a> rather than href="javascript:void();" 1,如果您的锚实际上没有将用户带到任何地方,请考虑不要使用<a>而不是href="javascript:void();"
2, try not to mix javascript with html. 2,尽量不要将javascript与html混合使用。 so link your event handler to the DOM element in a <script> tag. 所以将您的事件处理程序链接到<script>标记中的DOM元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM