jquery dynamic loading of JS three methods examples

Source: Internet
Author: User
Tags getscript
Here for you to provide three kinds of dynamic loading JS jquery instance code Oh, because jquery is to provide users with convenience, so the use of jquery dynamic loading files as long as a word $.getscript ("test.js"); OK. Copy Code code as follows:

<!doctype HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ""
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>jquery dynamically load JS three methods </title>
//Method one
<script language=" Web Effects ">
$.getscript ("Test.js");
//Method two
function Loadjs (file) {
     var head = $ (' head '). Remove (' #loadscript ');
& nbsp;   $ ("<scri" + "pt>" + "</SCR" + "ipt>"). attr ({src:file,type: ' text/javascript ', ID: ' Load '}) . Appendto (head);
//Easy enough! If you can even use one line of code in the condensed below:
//Method three
$ ("<scri" + "pt>" + "</SCR" + "ipt>"). attr ({src:file,type: ' text/ JavaScript ', ID: ' Load '}. Appendto ($ (' head '). Remove (' #loadscript '));

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.