现需要动态加载EasyUI组件,因为我的页面内嵌于iframe
通过如下方式可正确加载,且组件生效
var script = parent.document.createElement("script");
script.type = "text/javascript";
script.src = "easyUI/jquery.easyui.min.js";
parent.document.getElementsByTagName("head")[0].appendChild(script);
现想将其改为如下形式可正确加载,但组件未生效
$.getScript("easyUI/jquery.easyui.min.js", function( data, status, jqXHR ) {
});
显示 $("#win").window is not a function 且原型链中确实没有加载到组件
有前辈遇到过类似的问题吗?或者我该从何排查起呢?
官方API中对该方法有如下描述
The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page.
是不是因为第一种方式是加载到了iframe所在的head,而第二种方式是加载到了顶层head呢?
你第一种的方式
parent.document
这个是在父页面进行的操作。而第二种则是在当前页面进行的操作,肯定不一样了。