当前页面: 开发资料首页 → J2EE 专题 → 如何获取 鼠标 所在的 table中 的row 的编号
如何获取 鼠标 所在的 table中 的row 的编号
摘要: 如何获取 鼠标 所在的 table中 的row 的编号
本来是用隐藏的一个 来记录的
但是当鼠标挪走后,
这个值没有被置空
有没有好的解决方案?
在线等中 谢谢
b/s or c/s?
B/S:
<script>
var rowId;
</script>
<tr onmouseover="this.rowId=1;">.....
b/s的
用onclick 表示选择的行
不用onmouseover
补充移走事件:
<script>
var rowId;
</script>
<tr onmouseover="this.rowId=1;" onmouseout="this.rowId=-1;">.....
onmouseover改成onclick也是可以的,不过我喜欢onmouseover.
如果鼠标 找个空白的地方一点
这个时候rowId 还是原来的值,
需求是 rowId变为空
<script>
var rowId;
</script>
<body onclick="this.rowId=-1;">
<tr onmouseover="this.rowId=1;">.....
这样一搞
连 tr上的onchick也 激发了 body的onclick
造成了最终 点击 行的时候 结果就是-1了
tr上是onmouseover,不是onclick
如果你要都做onclick
要先判断事件源是什么.
if(event.srcElement.tagName == 'TR')
retrun;
else if(event.srcElement.tagName == 'BODY')
this.rowId=-1;
这个解决方案感觉不好
如果在body外面点击 还是不行呀
以前做个菜单,在它的回收事件,我们考虑了很多.
body外面,iframe外面,对话框外面......
虽然要写很多,但也根本没办法.
b/s开发就是这么复杂.
呵呵 无论如何 先谢谢了