好吧,我正在开展项目工作,我正在进行第二项工作,我已经开始讨论切换问题了,我似乎无法做到这一点。
document.getElementsByClassName("buttons")[1].onmousedown=
function(){
colorchange();
};
}
function colorchange() {
/*var background = function blue(){document.getElementsByClassName("buttons")[1].style.border;*/
if (getElementsByClassName("buttons")[1].style.border == "5px #c90 solid") {
document.getElementsByClassName("buttons")[1].style.border="5px blue solid";
} else {
if (getElementsByClassName("buttons")[1] == "5px blue solid") {
document.getElementsByClassName("buttons")[1].style.background = "5px #c90 solid";
}
}
}
答案 0 :(得分:0)
您所在的行:
if (getElementsByClassName("buttons")[1] == "5px blue solid")
应该是:
if (getElementsByClassName("buttons")[1].style.border == "5px solid blue")
答案 1 :(得分:0)
这是一种方法:
window.onload = init;
var stateTwo = false, colorsThree = ['#cc9900','#1e3a03','#611790'];
function init(){
var btns = document.getElementsByClassName("buttons");
btns[0].onmousedown = btns[0].onmouseup = funcOne;
btns[1].onclick = funcTwo;
btns[2].onclick = funcThree;
}
function funcOne(e){
this.style.background = ( e.type == 'mouseup' )? '#336600' : '#bd270a';
}
function funcTwo(e){
stateTwo = !stateTwo;
this.style.borderColor = stateTwo ? '#0c1583' : '#cc9900';
}
function funcThree(){
colorsThree.push( colorsThree.shift() );
this.style.borderColor = colorsThree[0];
}