意外的令牌')',流氓paranthes没有什么地方找到
我有一个简单的脚本,可以动态生成按钮。单击按钮在控制台中生成错误消息:“ us offult syntaxerror:意外的令牌')”(在(索引):1:8)”。为什么要生成此错误?如何防止它?
<button onclick="delete();">A Pet</button>
I have a simple script that dynamically generates buttons. Clicking on a button generates an error message in the console: "Uncaught SyntaxError: Unexpected token ')' (at (index):1:8)". Why is this error being generated, and how do I prevent it?
<button onclick="delete();">A Pet</button>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
delete
是一个关键字,无效作为函数名称。当JS引擎遇到delete()
在单击处理程序主体中,它将其解释为delete
语句应用于()
,这是一个空表达式,句法无效。要修复,请使用非关键字名称。请注意,最好使用
addeventListener
而不是内联手写处理程序。delete
is a keyword, and not valid as a function name. When the JS engine encountersdelete()
in the click handler body, it interprets it as adelete
statement applied to()
, which is an empty expression, and syntactically invalid.To fix, use a non-keyword name. Note that it might be better to use
addEventListener
instead of an inline handler.