html5载入JS引用「建议收藏」

html5载入JS引用

大家好,又见面了,我是全栈君。

直接上代码

w文件

<?xml version=”1.0″ encoding=”UTF-8″?

>

<div xmlns=”http://www.w3.org/1999/xhtml” xid=”window” class=”window” component=”$UI/system/components/justep/window/window” design=”device:mobile”>  
  <div component=”$UI/system/components/justep/model/model” xid=”model”/> 
  <h1 xid=”h11″ style=”text:align:center;”>h1</h1>
  <a component=”$UI/system/components/justep/button/button”
  class=”btn btn-default” onClick=”importInnerBtnClick”>
    <i xid=”i1″></i>
    <span xid=”span1″>载入UI2,符合AMD规范的文件</span>
  </a>
  <a component=”$UI/system/components/justep/button/button”  class=”btn btn-default”
  label=”载入外网,符合AMD规范的文件” xid=”importOutterBtn” onClick=”importOutterBtnClick”>
     <i xid=”i2″></i>
     <span xid=”span2″>载入外网,符合AMD规范的文件</span>
  </a>
</d

JS文件

define(function(require){
var $ = require(“jquery”);
var justep = require(“$UI/system/lib/justep”);

var Model = function(){
this.callParent();
};
   Model.prototype.importInnerBtnClick=function(event){
  //载入UI2下,符合AMD规范的文件
  var path=”./AMD2″;
  require([path],function(m){
  m.fnOfAMD2();
  });
  
   }
   Model.prototype.importOutterBtnClick=function(event){
  var path=”http://localhost:8080/cn/wp-content/uploads/2015/04/outterAMD2.js”
       require([path],function(m){
      m.fnOfOutterAMD2();
       })
   }
return Model;
});

须要引用的JS文件

define(
function(require){
return{
fnOfAMD2:function(){
alert(“hello AMD2”);
}
};
});

程序中会出现两个button

引用外部js文件成功引用网络js文件失败

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116569.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号