JS's TextInput Event

Source: Internet
Author: User

A new event, called TextInput, was introduced in the "DOM3 level Event" specification. By specification, this event is triggered when a user enters a character in an editable region. The behavior of this textinput event to replace KeyPress is slightly different.

One of the differences is that any element that can get focus can trigger the Kepress event, but only the editable region can trigger the TextInput event.

The two extinput events are triggered only when the user presses a key that can enter the actual character, and the KeyPress event is triggered when the key that affects the text display is pressed (for example, backspace).

Because the TextInput event is primarily considered a character, its event object also contains a data property whose value is the user-entered character (not the character encoding). In other words, if the user presses the S key without pressing the file key, the Data property is "s", and if you press the key while holding down the file key, the value of data is "s".

Here is an example of using the TextInput event:

var eventutil = {
Getevent:function (event) {
Return event? Event:window.event;
},

Addhandler:function (element, type, handler) {
if (Element.addeventlistener) {
Element.addeventlistener (type, handler, false);
} else if (element.attachevent) {
Element.attachevent ("On" + type, handler);

} else {

Element["on" + type] = handler;
}
}
};
var textbox = document.getElementById ("MyText");

Eventutil.addhandler (textbox, "TextInput", function (event) {

event = Eventutil.getevent (event);
alert (event.data);

});

Copy Code


In this example, the characters inserted into the text box are displayed by a warning box.

Currently only SAFARI3 and Chrome browsers support TextInput events. As a result, this event may not be available in cross-browser development

JS's TextInput Event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.