使用void()时未捕获的SyntaxError:意外的令牌) [英] Uncaught SyntaxError: Unexpected token ) when using void()

查看:82
本文介绍了使用void()时未捕获的SyntaxError:意外的令牌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误,并设法将其缩小为:

I get this error and I've managed to narrow it down to:

<a href="javascript:void();" onclick="myFunction();">aaa</a>

这行代码现在是我的源代码中唯一的东西,但我仍然在标题中得到错误。知道为什么会这样吗?

That line of code is now the only thing in my source code and still I get the error in title. Any idea why so?

即使用适当的HTML元素(html,head,body等)包围,我仍然会抛出错误。如果我包含

Even when surrounded with the appropriate HTML elements (html, head, body etc) I am still thrown the error. The error shows up in Chrome dev console and via alert if I include a

window.onerror

函数。当 myFunction()方法实际存在时,也会发生这种情况。据我所知,上述陈述绝对没有任何问题。

function in the head tag. It also occurs when the myFunction() method actually exists. As far as I can gather, there is absolutely nothing wrong with that above statement whatsoever.

推荐答案

使用

<a href="javascript:void(0);" onclick="myFunction();">aaa</a>

void 需要一个参数。

有一个关于使用 void(0)的有趣讨论或其他技术此处

There's an interesting discussion on using void(0) or other techniques here.

这篇关于使用void()时未捕获的SyntaxError:意外的令牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆