To determine if the control has loaded the completed code _javascript tips

Source: Internet
Author: User
For example:
Copy Code code as follows:

<input id= "btnpost" type= "button" value= "button"/>


When the browser is parsing, the input label is loaded first, and then the IMG tag is loaded.
At this point, if you want to determine whether the IMG tag is loaded, you can add a script around the IMG tag, such as
Code
Copy Code code as follows:

<div id= "Loading" ></div>
<input id= "btnpost" type= "button" value= "button"/>
<script type= "Text/javascript" >
var msg = document.getElementById ("Imga");
if (msg = null) {
document.getElementById ("Loading"). InnerHTML = "Building picture control ...";//the settimeout function does not work here
}
</script>

<script> document.getElementById ("Loading"). InnerHTML = "";</script>

Note that the IMG tag before and after the JS code, the above JS code to get an IMG object, and then determine whether the object is empty, if it is empty, the description is not loaded, then prompts the user "is building picture control", the completion of the load will be prompted to hide information.
The above method applies to all controls or labels, but for controls or labels that have a onload event on their own (the event is triggered after the corresponding control or tag is loaded), we can encapsulate the code behind the IMG as a function for the onload call, as follows
Code
Copy Code code as follows:

<script type= "Text/javascript" >
function loadedimg () {document.getElementById ("Loading"). InnerHTML = "";}
</script>
<body >
<input id= "AutoComplete"/>
<div id= "Loading" ></div>
<input id= "btnpost" type= "button" value= "button"/>
<script type= "Text/javascript" >
var msg = document.getElementById ("Imga");
if (msg = null) {
document.getElementById ("Loading"). InnerHTML = "is picture control ...";//the settimeout function does not work here
}
</script>

</body>

As you can see from the code above, the code behind the IMG tag has been encapsulated into the Loadedimg method called by IMG's onload.
Which controls or labels have the onload event? I checked on the Internet, as follows (do not know all):
<body&gt, <frame>, <frameset>, <iframe>, , <link> <script>
All right, that's it, leave a message.
Related Article

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.