实现点击过的扭按对象变色,在HTML文档写入下面代码:
<button>aa11</button>
<input type="button" value="aa22" /><button>aa33</button>
<input type="button" value="aa" /><button>aa</button>
<input type="button" value="aa" /><button>aa</button>
<input type="button" value="aa" />
<form style="border: solid 1px red"><button>aa</button>
<input type="BUTTON" value="aa" /><button>aa</button>
<input type="BUTTON" value="aa" /><button>aa</button>
<input type="BUTTON" value="aa" /></form><div>aaaaaaa<button>aa</button>
<input type="BUTTON" value="aa" />aaaaaaaaa</div>
<script>
window.onload = function Init(array)
{
if(array == null)
{
Init(document.getElementsByTagName("INPUT"));
Init(document.getElementsByTagName("BUTTON"));
return;
}
if(!window.OnMouseOver) window.OnMouseOver = function()
{
if(this == window.currentButton) return;
this.style.backgroundColor = "red";
this.style['color']='#00ff00';
}
if(!window.OnMouseOut) window.OnMouseOut = function()
{
if(this == window.currentButton) return;
this.style.backgroundColor = this.style.__backgroundColor;
}
if(!window.OnClick) window.OnClick = function()
{
if(window.currentButton) window.currentButton.style.backgroundColor = window.currentButton.style.__backgroundColor;
this.style.backgroundColor = "blue";
this.style['color']='#0000ff';
window.currentButton = this;
}
var length = array.length;
var btn;
for(var i = 0; i < length; i++)
{
btn = array[i];
if(btn.tagName != "BUTTON" && (btn.tagName != "INPUT" || btn.type != "button")) continue;
btn.style.__backgroundColor = btn.style.backgroundColor;
btn.onmouseover = window.OnMouseOver;
btn.onmouseout = window.OnMouseOut;
btn.onclick = window.OnClick;
}
}
</script>
