Jquery 我可以在加载新页面时加载js和css,并在导航到其他页面时卸载它吗

Jquery 我可以在加载新页面时加载js和css,并在导航到其他页面时卸载它吗,jquery,jquery-mobile,cordova,ibm-mobilefirst,Jquery,Jquery Mobile,Cordova,Ibm Mobilefirst,我正在使用Worklight 6.0和 WL.Page.load("templates/a.html", { onComplete : function() { console.log("After fragment is loadded "); }, onUnload : function() { console.log("After fragment is unloadded "); }

我正在使用Worklight 6.0和

 WL.Page.load("templates/a.html", {
        onComplete : function() {
          console.log("After fragment is loadded ");
        },
        onUnload : function() {
          console.log("After fragment is unloadded ");
        }
      });  
为了加载新页面并在onComplete方法中定义一些函数,我将所有css和js都放在索引页面上,这与其他页面冲突。我不希望所有的css和js都在一个页面上,而不是在加载新页面时加载它,在加载其他页面时卸载它。
我应该怎么做。

WL.Page API已被弃用,请改用$.load()。
请参见此处的培训模块和示例-

仅供参考,Worklight V6中已弃用了WL.Page.Load,而使用本机JavaScript和移动框架方法加载片段

您没有提到是否正在使用移动框架,但我使用了以下内容来加载dojo移动小部件的css:(domConstruct是:“dojo/domConstruct”)

对于jQuery,答案似乎如下:

我设想,您可以将css附加到片段上,而不是附加到文档头上,以便在片段卸载时将其卸载。这里有一个关于这是否合法的争论:当然,您可以在加载时将链接附加到头部,并在片段卸载时显式删除它

如果您使用dojo mobile并将JavaScript组织到模块中,则无需显式加载*.js文件。只需使用require()按需加载所需内容

对于使用jQuery mobile的用户,Require.js()也有类似的用途

var link1 = domConstruct.create("link", {
    type : "text/css",
    rel : "stylesheet",
    href : "js/widget/themes/myCss1.css"
});
var link2 = domConstruct.create("link", {
    type : "text/css",
    rel : "stylesheet",
    href : "js/widget/themes/myCss2.css"
});

var head = document.getElementsByTagName("head")[0];
head.appendChild(link1);
head.appendChild(link2);