Test the browser environment:
Chrome version 43.0.2357.134 m
Firefox version 24.0
IE6 (green version IE.exe)
IE7
IE8
IE9
Sogou Pinyin Input Method 3.5 (3.5.0.1089) Internet cafes dedicated installation version
Code:
<!DOCTYPE HTML><HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>Example</title> </Head> <Body> <inputtype= "text"ID= ' input '/> <DivID= ' div '></Div> <Scripttype= ' Text/javascript '> varINP=document.getElementById ('input'); varDiv=document.getElementById ('Div'); Inp.onkeydown= function() {div.innerhtml=Inp.value; Console.log (1); } </Script> </Body></HTML>
Results:
1:keyup
IE9 IE8 IE7 IE6 Firefox performance is good but always press the key, do not release the words, Div will not change in real time, until the last release will change, in fact, because your key is not up.
If you use the Sogou input method in chrome, input aaaaaa, not by the space or enter the confirmation, Div will also change in time.
2:keydown
IE9 IE8 IE7 IE6 Firefox chrome is not doing well,The first time you enter text (such as a pure English number a), there is no text display in the Div, the delay is obvious. (note that at this point the KeyDown event is triggered, but not in time to get the value in the input box, that is, it will execute code console.log (1))IE9 IE8 IE7 IE6 FirefoxSogou Input Method, enter Chinese characters, enter the end of the press Return or space, Div has no textChromeSogou Input Method, enter Chinese characters, if you press ENTER below the letter real-time appear normal,If you press a space, the div is still a letter, and input is a Chinese character. The improved scheme is to write a settimeout (function () {$ ("div"). Text (this.value);}, 0) IE9 IE8 IE7 IE6 Firefox is performing well, has been pressing the key does not release, can also be changed in real time. But for Chrome's Sogou input, click on the Space, sometimes the text box is a Chinese character, the following is still a letter. 3. KeyPressIE9 IE8 IE7 IE6 Firefox chrome is not doing well,The first time you enter text (such as a pure English number a), there is no text display in the Div, the delay is obvious. Sogou Input method, enter Chinese characters, enter the end of a press Enter or space, div no text press Backspace Delete key,Div does not change, only Firefox behaves normally. If solved with setTimeout.Press Backspace Delete key, the div still does not change (only Firefox behaves normally). sogou Pinyin IME Input AAAAA press Enter and space below the DIV content will not have any changes. Summary: Compatibility is better keyup. When you focus your cursor on input, it is best to set a setinterval timer that monitors the changes in values as it is entered continuously in input. And another solution: ie under the Onpropertychange, and other browsers with input or there will be compatibility issues, not recommended. (A little forgot what is the problem, you should still not get the value in the input box immediately)
KeyUp keydown keypress Difference