开发者

tinyMCE alert what you just wrote

开发者 https://www.devze.com 2023-04-09 14:31 出处:网络
In the tinyMCE init editor, How can i in setup do: ed.onKeyDown.add(function (ed, evt) { // alert the character you just typed

In the tinyMCE init editor,

How can i in setup do:

      ed.onKeyDown.add(function (ed, evt) {
         // alert the character you just typed
      });

Say if you type "a" a alert sh开发者_如何学Pythonould come up with "a"


The evt.keyCode property contains the code of the pressed key, so you can do this:

alert(String.fromCharCode(evt.keyCode));

Note, however, that this will also trigger an alert when a special key is pressed (e.g. shift), so you might want to prevent that by checking other properties of the evt object (which is an instance of DOM Event). See the documentation for keyboard event objects at https://developer.mozilla.org/en/DOM/KeyboardEvent.

Edit: Use onKeyPress instead of onKeyDown, as onKeyDown might return incorrect key codes in some browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消