我有一个按钮可以在这个之外工作,但我真的想用一个普通的 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>
......我做错了什么?
最佳答案
你必须调用这个函数,如果你直接在 onclick 属性中包含这个函数,你必须像这样使用立即函数,尽管下面你必须定义第一个编辑器
<div style="background-color:red; width:50px; height: 50px;" onclick='(function () { editor.insertText("\\≥\\"); }());'></div>
关于javascript - 内联 onclick 事件返回 "Uncaught SyntaxError: Unexpected token ( "错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25091621/