网络编程
位置:首页>> 网络编程>> JavaScript>> jquery实现不同大小浏览器使用不同的css样式表的方法

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

  发布时间:2024-04-10 10:34:53 

标签:jquery,css样式表

该方法支持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());
    });
});


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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com