代码如下:
<div class="top_center" id="oChange">
<ul>
<li>
<a href="#" color="1"></a>
</li>
<li>
<a href="#" color="2"></a>
</li>
<li>
<a href="#" color="3"></a>
</li>
</ul>
</div>
js代码如下:
window.onload = function () {
oColor();
}
var oClor = document.getElementById('oChange');
var oA = oClor.getElementsByTagName('a');
var ocl;
var css = document.getElementById('css');
function oColor() {
oA[0].style.background = '#ff9d00';
oA[1].style.background = '#90EE90';
oA[2].style.background = '#33cfaf';
for (var i = 0; i < oA.length; i++) {
oA[i].onclick = function () {
for (var i = 0; i < oA.length; i++) {
oA[i].style.border = '';
}
this.style.border = 'solid 2px #CCC';
if (this.style.borderStyle == 'solid') {
// ocl = this.getAttribute('color');
$.cookie("style", $(this).attr(":color"));
if ($.cookie("style") == "1") {
css.setAttribute('href', 'css/header-b.css');
} else if ($.cookie("style") == "2") {
css.setAttribute('href', 'css/header-a.css');
} else if ($.cookie("style") == "3") {
css.setAttribute('href', 'css/header-c.css');
}
已实现点击按钮切换css样式表,之后用cookie进行操作,大神指导下...
丶包菜
相关分类