jquery为下一页更改css

jquery to change css for next page

本文关键字:css 一页 jquery      更新时间:2023-09-26

我有一个名为android.html的页面,其中有一个id为"detect"的按钮。当你点击按钮时,脚本会通过us标头检查你的android设备上的操作系统版本。如果是3.0或更高版本,我该如何更改脚本以应用一种样式,如果是2.9或更低版本,我将如何更改另一种样式。这是最难的部分。。。我不想将css样式应用于android.html页面,而是应用于您单击按钮后将重定向到的playlist.html页面。

html

<div id="detect">button</div>

js

$('#detect').click(function() {
if (/Android ('d+(?:'.'d+)+)/.test(navigator.userAgent)){ 
 var version=new Number(RegExp.$1) 
 if (version>=3)
  //redirect to playlist.html using style1.css
 }
else
 //redirect to playlist.html using style2.css
});

在重定向中附加一个查询字符串键/值对,让下一页知道要加载哪个样式表,或者在加载下一页时只检查用户代理字符串。

$('#detect').click(function() {
    if (/Android ('d+(?:'.'d+)+)/.test(navigator.userAgent)){ 
        var version=new Number(RegExp.$1) 
        if (version>=3)
            window.location = 'playlist.html?style=1';
        } else {
            window.location = 'playlist.html?style=2';
        }
    }
});

然后在playlist.html页面上:

if (window.locaion.search.indexOf('style=1') > -1) {
    $.getScript('style1.css');
} else if (window.locaion.search.indexOf('style=2') > -1) {
    $.getScript('style2.css');
}

这个if/then检查非常简单。更好的方法是获取数组中的查询字符串参数,检查style键,然后加载相应的值。

重定向到带有查询字符串的html页面,即playlist.html?css=v1或v2,然后在下一页中检查该GET参数,并包含相应的css文件。

可能需要将一个查询字符串变量传递给指定"anversion"的重定向,然后检查该变量并根据第二页上的值插入.css文件。