改变按钮样式:JS鼠标操作

本文探讨了ASP.NET页面中按钮与自定义div元素的交互事件处理,通过JavaScript脚本实现鼠标悬停、点击及按下状态的动态样式变化,展示了前端开发中交互与样式的动态管理技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前台页面: 

ExpandedBlockStart.gif 代码
< asp:Button ID = " Button1 "  runat = " server "  Text = " Button "  CssClass = " CommonButton "   />
  
< br  />
< div id  = " btColor "   class   = " CommonButton "  onclick = " OnMouseDown() "  onmouseover = " OnMouseEnter() "  onmouseout = " OnMouseLeave() " > click me
</ div >

 

JS脚本:

ExpandedBlockStart.gif 代码
< script src = " ClientLibrary.js "  type = " text/javascript " ></ script >
    
< script type = " text/javascript " >
        function OnMouseEnter() {
            var div 
=  document.getElementById( " btColor " );
            div.className 
=   " FloatButton " ;
        }
        function OnMouseLeave() {
            var div 
=  document.getElementById( " btColor " );
            div.className 
=   " CommonButton " ;
        }
        function OnMouseDown() {
            var div 
=  document.getElementById( " btColor " );
            div.className 
=   " PressdownButton " ;
        }

function Button(controlID) {
    debugger;
    
this .Init  =  function () {
        var button 
=  document.getElementById(controlID);
        alert(button);
        button.onclick 
=  function () {
            button.className 
=   " PressdownButton " ;
            
return   false ;
        }
        button.onmouseover 
=  function () {
            button.className 
=   " FloatButton " ;
        }
        button.onmouseout 
=  function () {
            button.className 
=   " CommonButton " ;
        }
    }
}
        var button 
=   null ;
        window.onload 
=  function () {
            button 
=   new  Button( " Button1 " );
            button.Init();
        }
    
</ script >

转载于:https://www.cnblogs.com/caoshuai/archive/2010/07/11/1775266.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值