简体   繁体   中英

javascript syntax for keypress

I'm trying to learn javascript and I cannot figure out what's wrong with the following simple code.

function typeCatch() {
    alert("key pressed");
}

$(function () {
    $("textarea.redactor_editor").on("keypress", typeCatch);
});

Basically you would get an alert message everytime you write something in the provided form.

  1. What's wrong with this code? typeCatch() isn't called when I'm typing in the form.
  2. How would I debug this if a similar problem happened? Nothing shows up in the console box in firebug.

http://jsfiddle.net/4wmup/1/

This code is using JQuery. Try setting the JSFiddle to one of the JQuery libraries instead of just Javascript. (Top-left of the screen)

Cheers, LC

Is your textarea actually a rich text editor, using some other library (like redactor)?

Rich text editors usually hide the actual textarea, and show you a rich text interface that they create instead - so you're not actually typing in the textarea.

Depending on which rich text editor you're using, there may be a different (supported) way to hook in a keypress event handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM