HTML code:
----------------------
<Html>
<Head>
<Script>
// Synchronous Function
Function synchronize (){
Document. getElementById ('i1'). value = document. getElementById ('i2 '). value;
// Alert ("synchronization successful ");
}
// Execute Synchronization
SetInterval (synchronize, 500); // synchronization interval, which is synchronized every 0.5 seconds
</Script>
</Head>
<Body>
If you enter a character in the second input box, it is automatically synchronized to the first input box. <Br/>
The first input box: <input type = "text" size = "45" id = "i1" name = "first"> <br/>
The second input box: <input type = "text" size = "45" id = "i2" name = "second">
</Body>
</Html>
Save the preceding HTML code as an html file and open it in a browser to see the effect. Note: Some browsers prohibit local scripts for security reasons. Click "run.
In the process of searching data, we find that not only the change event can be handled, but other events can also be handled. For example, keyup events. Here is another example:
Www.2cto.com
// This is not a real-time change
<Input type = "text" id = "t1" value = "" size = "45" onchange = "document. getElementById ('t2 '). value = this. value "/>
<Input type = "text" id = "t2" value = "" size = "45" onchange = "document. getElementById ('t1 '). value = this. value "/>
// This is a real-time change, but it won't be detected if you use the mouse to mark it, so you can combine the two.
<Input type = "text" id = "t3" value = "" size = "45" onkeyup = "document. getElementById ('t4 '). value = this. value "/>
<Input type = "text" id = "t4" value = "" size = "45" onkeyup = "document. getElementById ('t3 '). value = this. value "/>
Author: Heng_Ji