【已解决】requireJS 加载 layer.js时,使用layer.load无法显示提示弹窗问题
首页引用layer.js
一般在html时,直接引入就可以调用layer的方法。但是requireJS比较特殊,使用layer.load时,发现根本没有加载显示弹窗;
后面网上搜索了下,是因为requireJS在加载模块layer时,是不加载css文件的,所以需要在config配置里,增加css进行即可;
requireJS加载css时,需要引入css.min.js文件,才能在shim里引入css文件,否则报错;
由上图可以看到,先引入css.min.js后,再到shim定义layer.deps引入相应的css(好像这里只能写绝对路径,如果谁有简捷的方法,可评论在下方。谢谢...)
css.min.js
define(function(){if("undefined"==typeof window)return{load:function(a,b,c){c()}};var a=document.getElementsByTagName("head")[0],b=window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)|AndroidWebKit\/([^ ;]*)/)||0,c=!1,d=!0;b[1]||b[7]?c=parseInt(b[1])<6||parseInt(b[7])<=9:b[2]||b[8]?d=!1:b[4]&&(c=parseInt(b[4])<18);var e={};e.pluginBuilder="./css-builder";var f,g,h,i=function(){f=document.createElement("style"),a.appendChild(f),g=f.styleSheet||f.sheet},j=0,k=[],l=function(a){g.addImport(a),f.onload=function(){m()},j++,31==j&&(i(),j=0)},m=function(){h();var a=k.shift();return a?(h=a[1],void l(a[0])):void(h=null)},n=function(a,b){if(g&&g.addImport||i(),g&&g.addImport)h?k.push([a,b]):(l(a),h=b);else{f.textContent='@import "'+a+'";';var c=setInterval(function(){try{f.sheet.cssRules,clearInterval(c),b()}catch(a){}},10)}},o=function(b,c){var e=document.createElement("link");if(e.type="text/css",e.rel="stylesheet",d)e.onload=function(){e.onload=function(){},setTimeout(c,7)};else var f=setInterval(function(){for(var a=0;a<document.styleSheets.length;a++){var b=document.styleSheets[a];if(b.href==e.href)return clearInterval(f),c()}},10);e.href=b,a.appendChild(e)};return e.normalize=function(a,b){return".css"==a.substr(a.length-4,4)&&(a=a.substr(0,a.length-4)),b(a)},e.load=function(a,b,d,e){(c?n:o)(b.toUrl(a+".css"),d)},e});
相关推荐
aganliang 2020-02-02
Chasingsun 2013-05-16
Elna 2020-01-09
binglingnew 2019-12-03
lancelotlewis 2014-01-21
FruitHardCandy 2015-03-04
小新正在敲代码 2015-10-22
小新正在敲代码 2016-04-14
人生百态 2017-09-26
jethai 2019-07-01
Joyine 2019-07-01
earthhour 2019-06-30
Chasingsun 2019-06-30
lancelotlewis 2019-06-29
qianqinggang 2019-06-29
jjjjjj 2019-06-29
qianqinggang 2019-06-28
FoolishInfanta 2016-11-08
YOKOELEMENT 2016-09-28