The instance method of the content of the JS Code synchronization text Box _javascript tips

Source: Internet
Author: User
Tags instance method time interval

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 "/>

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.