我想修改以下功能,根据User $ _COOKIE ['theme']在2个主题(光线或对比度)之间首先运行
例如我已经有了这个输出
$_COOKIE['theme'] = contrast
如何修改它以配合我的想法?
<script type="text/javascript">
function setTypeLight(type)
{
$('body').removeClass('black');
$('.wtop .account li.menu .menu_inner a.typelight').removeClass('light contrast');
$('.wtop .account li.menu ul li').removeClass('act');
switch (type)
{
case 'light':
$('.wtop .account li.menu .menu_inner a.typelight').addClass('light');
$('.wtop .account li.menu ul a.typelight.light').parent('li').addClass('act');
break;
case 'contrast':
$('body').addClass('black');
$('.wtop .account li.menu .menu_inner a.typelight').addClass('contrast');
$('.wtop .account li.menu ul a.typelight.contrast').parent('li').addClass('act');
break;
}
ajaxLoad({id: '#', url: '/top/ajax.php?action=param¶m=typelight&typelight=' + type + '&sessid=9e6c'}, {nprogress: 'N', type: 'null'});
}
</script>
<li><a href="?theme=light" onClick="setTypeLight('light'); return false;" class="typelight light">light</a></li>
<li><a href="?theme=contrast" onClick="setTypeLight('contrast'); return false;" class="typelight contrast">contrast</a></li>
答案 0 :(得分:0)
只需致电获取您的cookie并在启动时调用您的功能
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$(function(){
setTypeLight(getCookie('theme'));
});