• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

奋斗中...

曾经的程序员。ASP.NET/C#, JavaScript, PL/SQL, T-SQL; 工具: VS2003/2005, Oracle, SQLServer; 偶尔写点CSS, 批处理.
头脑中经常有新想法, 可惜没有去实现.
Never give up.
Never get into a fight with a pig. Both of you will get dirty. But the pig actually enjoys it.
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

[整理]怎么判断鼠标左键按住不放

怎么判断鼠标左键按住不放,比如:按住鼠标左键进行文本选定操作;鼠标写字等。整理自:http://topic.csdn.net/u/20091125/14/f7fd42d7-fb20-4acc-9623-3f5640c19411.html

整理自:http://topic.csdn.net/u/20091125/14/f7fd42d7-fb20-4acc-9623-3f5640c19411.html

比如:按住鼠标左键进行文本选定操作;鼠标写字等。

Click_Me 提供以下代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "  http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="  http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="textml; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<div id="odiv" style="width:100px; height:100px; border:1px solid red">按住鼠标移上来</div>
<script type="text/javascript">
<!--
    var isBound = false;
    document.onmousedown = function(){
        isBound = true;
    }
    document.onmouseup = function(){
        isBound = false;
    }
    document.getElementById('odiv').onmouseover = function(){
        if(!!isBound)  this.style.backgroundColor = 'blue';
    }
//-->
</script>
</body>
</html>

其实,给控件绑定onmouseover事件,如果页面上多个控件需要此功能的话,就很麻烦。可以设置document.onmouseover事件,并通过window.event.srcElement(firefox下是event.target)当前事件的元素,来给当前控件提供功能。

posted on 2011-02-16 10:02  jes  阅读(972)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3