内联onclick事件返回一个“未捕获的syntaxError:意外令牌(”错误
-
02-01-2020 - |
题
我有一个按钮在此之外工作,但我真的想用正常div复制动作。只需添加此ClickHandler:
即可这样做 editor.insertText("\"≥\"");
.
到onclick事件。我想将该片段添加到内联div,但我一直从以下div中获得“Uncaught SyntaxError: Unexpected token (
”错误:
<div style="background-color:red; width:50px; height: 50px;" onclick='function () { editor.insertText(\\≥\\); }'></div>
.
......我做错了什么?
解决方案
试试:
<div style="background-color:red; width:50px; height: 50px;" onclick='editor.insertText("\"≥\"");'></div>
. 其他提示
您必须调用该函数,如果您在onclick属性中直接包含函数,则必须使用这样的立即函数,但下面您必须定义哪个编辑器首先
<div style="background-color:red; width:50px; height: 50px;" onclick='(function () { editor.insertText("\\≥\\"); }());'></div>
. 不隶属于 StackOverflow