jquery实现不同大小浏览器使用不同的css样式表的方法 |
本文标签: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()); }); }); 以上代码经过测试可用!! |