当前位置DIV+CSS >> 激活的当前对象(buttom按钮)变色JS代码

激活的当前对象(buttom按钮)变色JS代码

实现点击过的扭按对象变色,在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>

 

评论

相关文章more

深圳品牌策划 广告策划 深圳VI设计 深圳画册设计 网页设计 VI设计 网络优化 深圳网站优化 网络推广 画册设计 网站建设 网站优化 Copyright © 2008 www.torwei.com All Rights Reserved.    客服邮箱:wyechoi@hotmail.com
地址:深圳市福田区福华路拓威网络    邮编:518000   链接服务

网站优化,网络推广,关键字优化,搜索引擎排名