インラインonClickイベント "ConcaughtのSyntaxError:予期しないトークン("エラー)を返します。

StackOverflow https://stackoverflow.com//questions/25091621

  •  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>
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top