JS厉害的进吧
这是方法,当选择任何一个div的时候将会触发的方法
function change1(ok){
document.getElementById(ok).style.background= "Lavender ";
}
我有10个div,选择其中1个以后让其他9个的样式为:
document.getElementById(ok).style.background= "white ";
[解决办法]
<div id= "a1 " onmousedown= "change1(this.id); "> 11111111 </div> <div id= "a2 " onmousedown= "change1(this.id); "> 22222222 </div> <div id= "a3 " onmousedown= "change1(this.id); "> 333333 </div> <div id= "a4 " onmousedown= "change1(this.id); "> 555555 </div> <div > 其他 </div> <script type= "text/javascript "> function change1(id) { var divs = document.getElementsByTagName( "div "); for(var i=0;i <divs.length;i++) { if( divs[i].onmousedown!= null && divs[i].onmousedown.toString().toLowerCase().indexOf( "change1 ")> -1) { divs[i].style.backgroundColor= "red "; } } } </script>