我一直在关注 javascript css 切换器的 Kevin Luck 示例。 http://www.kelvinluck.com/assets/jquery/styleswitch/index.html
我让它在我的本地项目上工作。我的问题/问题是,当我使用 Kevin Luck 使用的旧 javascript 时,它可以工作。当我尝试更新 jQuery 版本时,它会中断。如何更新此示例以使用最新的 1.10.2 jQuery?
索引页面看起来像这样(相关部分)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Public Identity</title>
<link rel="stylesheet" type="text/css" href="css/collegeStyles.css" title="college" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="css/corporateStyles.css" title="corporate" media="screen" />
<!-- Google CDN jquery -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<!-- // <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> -->
<!-- css style switcher -->
<script type="text/javascript" src="styleswitch.js"></script>
jQuery (styleswitcher.js) 看起来像这样
/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/
(function($)
{
$(document).ready(function() {
$('.styleswitch').click(function()
{
switchStylestyle(this.getAttribute("rel"));
return false;
});
var c = readCookie('style');
if (c) switchStylestyle(c);
});
function switchStylestyle(styleName)
{
$('link[@rel*=style][title]').each(function(i)
{
this.disabled = true;
if (this.getAttribute('title') == styleName) this.disabled = false;
});
createCookie('style', styleName, 365);
}
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name)
{
createCookie(name,"",-1);
}
// /cookie functions
唯一相关的 CSS 是样式表名称,它们被称为学院和公司。您可以在上面的 php/html 代码中看到它们。我很困惑为什么这会中断,并且不知道如何解决。任何想法都会非常有帮助。谢谢!