您的位置:首页 > Web前端 > JQuery

jquery实现不同大小浏览器使用不同的css样式表的方法

2018-10-12 14:01 471 查看

该方法支持IE浏览器和其他浏览器。

1、首先定义两个link,当然你也可以是一个,第二个是要更改的css


<link rel="stylesheet" type="text/css" href="main.css" />
<link id="size-stylesheet" rel="stylesheet" type="text/css" href="narrow.css" />

2、下面的JavaScript代码将根据不同的浏览器大小,更改css
function adjustStyle(width) { 
    width = parseInt(width);
    if (width < 701) {
        $("#css").attr("href", "css/narrow.css");
    } else if ((width >= 701) && (width < 900)) {
        $("#css").attr("href", "css/medium.css");
    } else {
       //$("#css").attr("href", "<?php bloginfo('stylesheet_url'); ?>");
       document.write("css/style.css")
    }
}
$(function() {
    adjustStyle($(this).width());
    $(window).resize(function() {
        adjustStyle($(this).width());
    });
});

以上代码经过测试可用!!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: