我找到了很多解决方案,但没有一个起作用。.
我有这个:
$(document).ready(function(){
if ( $(window).width() > 480) {
}
});
我想知道的是,当窗口宽度大于480px但小于768px时,如何将外部js文件加载到html头中。我尝试使用“加载”和“写入”,但没有一个起作用。
提前感谢!
$(document).ready(function(){
if ( $(window).width() > 480 && $(window).width() < 768) {
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
}
});
// I loaded value between 901 to 1600 width, You can run with your min-width or max-width
jQuery(document).ready(function($){ // Or else use with your requirment function (ex.$(window).on('load') or click function etc.)
var windowsize = $(window).width();
if ((windowsize >= 901) && (windowsize <= 1600)) {
//Do Your Code Here...
}
});