How to dynamically import a JS file how to implement the specific

Source: Internet
Author: User
Tags eval html page root directory

  How you need to dynamically import JS files, the following methods may help you

When we want to do dynamic import JS file, we can use the following method     code as follows: var docfunc = {   /****************************************   * Purpose: Invoke the following dynamic load script method load_script  ****************************** /    loaddefjquery:function () { //alert ( Ucapsession.hostpath + ucapsession.apppath);   //ucapsession.apppath is the root directory   Docfunc.load_script ( ucapsession.apppath  + "Ftdxxglxt/js/jquery-1.8.1.min.js");  Docfunc.load_script (UcapSession.appPath   + "Ftdxxglxt/js/jsuggest.js"); },   /******************************************************   * Purpose: Dynamically loading scripts   ************************************************************** /  load_script:function (URL) {  var x = new ActiveXObject ("Msxml2.xmlhttp");  x.open (' Get '), URL, False);  x.send (");  eval (x.responsetext);  var s = x.responsetext.split (/n/);  var r =/^ (?: Function|var) s* ([a-za-z_]+)/i;  for (var i = 0; i < s.length; i++)   {  var m = R.exe C (S[i]);  if (M!= null)   {  window[m[1] = eval (m[1)); } } }   }    In HTML page or JSP page Invoke method:    code as follows: <script>  docfunc.loaddefjquery ();  </script> 

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.