Home > Article > Web Front-end > webapp external css reference_html/css_WEB-ITnose
w文件:
JS file
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
//Load the css file under ui2
require("css!./innerCss1").load();
require ("css!$UI/demo/misc/importCss/innerCss2").load();
//Load the text file under UI2
var innerText1=require("text!./innerText1. txt");
var Model = function(){
this.callParent();
};
Model.prototype.modelLoad=function(event){
alert( "innertText1 content:" innerText1);
};
//Dynamic loading of text files under UI2
Model.prototype.innerTextBtnClick = function(event){
};
Model.prototype.span3Click = function(event){
var path = "text!./innerText1.txt";
require([path], function(content){
alert("innerText2 content: " content);
});
};
return Model;
});
css1:
.innerCss1{
background-color:red;
}
css2:
.innerCss2{
background-color:yellow;
}
txt file:
{message: "this is innerText1"}
x5 official explanation:
Code Implementation:
| define( function (require){ var $ = require( "jquery" ); var justep = require( "$UI/system/lib/justep" ); //Load the css file under UI2 require( "css !./innerCss1" ).load(); require( "css!$UI/demo/misc/importCss/innerCss2" ).load(); //Load the css file from the external network require( "css! http://wex5.com/cn/wp-content/uploads/2015/04/outterCss1.css" ).load(); ... }); |
Note: As shown in the code, in WeX5, the css file is referenced through require("css!xxx").load(). The parameters of require must comply with the following rules:
1. The parameter must be a constant starting with "css!";
2. The path supports the following situations: relative paths starting with "./" or "../" (relative to the path where the current js file is located ), no extension is required; the absolute path starting with "$UI/" ($UI represents the UI2 directory) does not require an extension; the absolute path starting with "http://" must have an extension (if any extension).
In WeX5, if you want to download a server-side text file, it is also achieved through the require mechanism, for example:
67 8 9 10 11 12 13 14 15 16 17 18 | //Load text files under UI2 var innerText1 = require( "text!./innerText1.txt" ); var Model = function (){ this .callParent(); }; Model.prototype.modelLoad = function (event){ alert( "innerText1 content: " innerText1); }; //Dynamic loading of text files under UI2 Model.prototype.innerTextBtnClick = function (event){ var path = "text!./innerText2.txt" ; require([path], function (content){ alert( "innerText2 content: " content); }); }; |