怎么判断鼠标在哪个控件上面?

skytouch_zyt 2002-12-29 06:49:34
比如说某个层,某个cell上面?
...全文
185 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
希默软件 2002-12-30
  • 打赏
  • 举报
回复
<body onmouseover=mouseover()>
<table border=1 id=a1>
<tr><td><input type=text name=txt1></td>
<td><input type=text name=txt2></td></tr>
</table>
<script>
function mouseover()
{
alert(a1.contains(document.elementFromPoint(event.clientX,event.clientY)))
}
</script>
</body>
liuzxit 2002-12-30
  • 打赏
  • 举报
回复
關于Table的情況你能怎樣呢?當鼠標屬于某個TD時也同時屬于TABLE﹐還有其他包含方式的標簽

判斷鼠標的位置有屬性
event.clientX和event.clientY

不如設一個全局變量﹐然后在onmouseover中把名稱傳給該變量

var activeE=''
document.onmouseover=fucntion(){activeE=event.srcElement.name}
wuziqi_puyue 2002-12-29
  • 打赏
  • 举报
回复
马马乎乎用用
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body onmouseover=mouseover()>
<input type=text name=txt1 >
<input type=text name=txt2 >
<script>
function mouseover()
{
if(window.event.clientX>txt1.offsetLeft && window.event.clientX<txt1.offsetLeft+txt1.offsetWidth && window.event.clientY>txt1.offsetTop && window.event.clientY<txt1.offsetTop+txt1.offsetHeight)
alert(event.srcElement.name)
}
</script>
</body>

</html>
wangyime 2002-12-29
  • 打赏
  • 举报
回复
那是因为你没有给table和a取name
skytouch_zyt 2002-12-29
  • 打赏
  • 举报
回复
我想获得当前鼠标的位置,然后判断是否在某个控件里面,怎么做?
楼上这位大虾的脚本我试过了,好像对于table a 这样的对象不好
用!!
wangyime 2002-12-29
  • 打赏
  • 举报
回复
<body onmouseover=mouseover()>
<input type=text name=txt1>
<input type=text name=txt2>
<script>
function mouseover()
{

alert(event.srcElement.name)
}
</script>
</body>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧