Home  >  Article  >  Web Front-end  >  Code to determine whether the control has been loaded_javascript skills

Code to determine whether the control has been loaded_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:33:59999browse

For example:

Copy code The code is as follows:




When the browser parses, it first loads the input tag and then the img tag.
At this time, if you want to determine whether the img tag is loaded, you can add a script before and after the img tag, such as
code
copy code The code is as follows:





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

Pay attention to the js code before and after the img tag at this time. The above js code first obtains the img object, and then determines whether the object is empty. If it is empty, it means that it has not been loaded. Once completed, the user will be prompted with "Generating Image Control", and the prompt information will be hidden after loading is complete.
The above method applies to all controls or labels, but for controls or labels that have onload events themselves (this event is triggered after the corresponding control or label is loaded), we can completely encapsulate the code behind the img into a The function is called by onload, as follows
Code
Copy code The code is as follows:

< script type="text/javascript">
function loadedImg() { document.getElementById("loading").innerHTML = ""; }










As you can see from the above code, the code behind the img tag has been encapsulated into the loadedimg method and is called by img's onload.
So which controls or labels have onload events? I checked it online and found the following (not sure if it is complete):
, , ,