HTML code:
Copy Code code as follows:
<script>
Synchronization functions
function Synchronize () {
document.getElementById (' I1 '). Value =document.getelementbyid (' I2 '). Value;
Alert ("Sync succeeded");
}
Perform synchronization
SetInterval (synchronize,500);//sync time interval, sync every 0.5 seconds
</script>
<body>
Entering a character in the second input box automatically synchronizes to the first input box. <br/><br/>
The first input box: <input type= "text" size= "id=" I1 "Name=" "a" ><br/><br/>
The second input box: <input type= "text" size= "id=" I2 "name=" Second ">
</body>
Save the HTML code as an HTML format file and open it in the browser to see the effect. Note: Some browsers are not allowed to execute local scripts for security purposes, please click "Run".
In the process of finding data, it is found that not only change events can be handled, but other events can also be handled. For example: KeyUp events, and so on. Here's another example fragment:
Copy Code code as follows:
This is not a change of immediacy.
<input type= "text" id= "T1" value= "size=" "onchange=" document.getElementById (' T2 '). Value=this.value "/>
<input type= "text" id= "T2" value= "size=" "onchange=" document.getElementById (' T1 '). Value=this.value "/>
This is a real-time change, but if you use the mouse to sign it, he won't detect it, so you can combine the top and bottom two.
<input type= "text" id= "T3" value= "size=" "onkeyup=" document.getElementById (' T4 '). Value=this.value "/>
<input type= "text" id= "T4" value= "size=" "onkeyup=" document.getElementById (' T3 '). Value=this.value "/>