Directory:Dynamicload class introduction, attributes, methods, events, examples, and downloads.
Introduction to dynamicload
This article will introduce you to a dynamicload class that can dynamically load JS, vbs scripts, and CSS style sheets in Javascript. The loading principle is divided into three steps: (1) Use document. createelement creates a script or style table object (hereinafter referred to as object O); (2) sets the attribute of object O; (3) adds the object to document. Using the dynamicload class, you can easily determine whether a script has been loaded, dynamically load the script, and other operations.
Attributes in the dynamicload class
Self -- object itself (this attribute is used during design,ProgramTo avoid using this attribute .)
Methods In the dynamicload class
Load (SRC) -- load the specified file. If the load succeeds, the onloaded event is triggered. If the load fails, the onfailed event is triggered. You can load the corresponding operation by reloading the callback functions loadedcallback and failedcallback.
Isloaded (SRC) -- determine whether the specified file has been loaded.
Getsrctype (SRC) -- get the file type (that is, the extension)
Loadedcallback (SRC)-the callback function executed after the file is loaded successfully. Reload this method to process operations after the file is loaded successfully.
Failedcallback (SRC): The callback function executed after file loading fails. Reload this method to process operations that fail to load files.
Events in the dynamicload class
Onloaded (SRC) -- Successful file loading event.
Onfailed (SRC) -- file loading failure event.
Example:
The following example shows how to determine whether a file has been loaded and how to dynamically load the file.
< Html >
< Body >
< Script Language = "JavaScript" Type = "Text/JavaScript" SRC = "Dynamicload. js" > </ Script >
< Script Language = "JavaScript" Type = "Text/JavaScript" >
<! --
VaR DL = New Dynamicload (); // Initialize a dynamicload object
Alert (DL. isloaded ( " Dynamicload. js " )); // Determine whether the file dynamicload. js has been loaded
DL. Load ( " Httpcookie. js " ); // Load httpcookie. js
Alert (DL. isloaded ( " Httpcookie. js " )); // Determine whether the file httpcookie. js has been loaded. Loading takes time. In general, false is returned here. If you judge after a short period of time, true is probably returned.
// -->
</ Script >
</ Body >
</ Html >
Download:
Download dunamicload
Thanks:
This article references the followingArticleThank you for your hard work.
A kind of dynamic loading JS file, watermarked http://hi.baidu.com/smvv21/blog/item/50156c0ef644bdcb7bcbe195.html
Dynamic Loading of external CSS or JS files ddcat http://homepage.yesky.com/45/7728545.shtml
Ray djajadinata http://msdn.microsoft.com/zh-cn/magazine/cc163419.aspx using object-oriented technology to create advanced Web Applications
Thank you for reading this article and hope to help you.