Code used to determine whether the control has been loaded

Source: Internet
Author: User

For example:
Copy codeThe Code is as follows:
<Input id = "btnPost" type = "button" value = "button"/>


When parsing, the browser first loads the input tag and then the img tag.
If you want to determine whether the img tag is fully loaded, you can add a script before and after the img tag, for example
Code
Copy codeThe Code is 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 = "generating image control..."; // the setTimeout function is not used here.
}
</Script>

<Script> document. getElementById ("loading"). innerHTML = ""; </script>

Pay attention to the js Code before and after the img label. The above js Code first obtains the img object and then determines whether the object is empty. If it is empty, the loading is not completed, the system prompts you to "generate an image control". After loading, the system hides the information.
The above method applies to all controls or labels, but for controls or labels with onload events (this event is triggered after the corresponding controls or labels are loaded ), we can encapsulate the code behind img into a function for onload to call, as shown below:
Code
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function loadedImg () {document. getElementById ("loading"). innerHTML = "";}
</Script>
</Head>
<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 = "picture control..."; // the setTimeout function is not used here.
}
</Script>

</Body>

From the code above, we can see that the code behind the img tag has been encapsulated into the loadedimg method and called by img onload.
Which controls or labels have onload events? I checked it on the internet as follows (I don't know if it's all complete ):
<Body>, <frame>, <frameset>, <iframe>, , <link>, <script>
There are so many problems.

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.