关于onclick中的event对象和element对象
对象 关于 Element Event onClick
2023-09-11 14:16:43 时间
event.srcElement:引发事件的目标对象,常用于onclick事件。
event.fromElement:引发事件的对象源,常用于onmouseout和onmouseover事件。
event.toElement:引发事件后,鼠标移动到的目标源,常用于onmouseout和onmouseover事件。
onmouseover时,srcElement相当于toElement;
onmouseout时,srcElement相当于fromSrcElement
小示例(兼容FF浏览器):
<mce:script type="text/javascript"><!--
function mouseoutHandler(oEvent,objTagName)
{
var oEvent = oEvent ? oEvent : window.event
var oElem = oEvent.toElement ? oEvent.toElement : oEvent.relatedTarget; // 此做法是为了兼容FF浏览器
alert(oElem.id); // 当鼠标移出Div1时,会弹出提示框提示鼠标移动到的另一个元素的ID
}
// --></mce:script>
<div onmouseout="mouseoutHandler(event)" id="div1" style=" width:50px; height:50px;">div1</div>
<div id="div2" style="width:50px; heigth:50px;" >div2</div>
相关文章
- 【很变态】PHP类实例化对象竟然可以访问类的“静态(static)方法”!!!
- 关于使用JAXB读取xml文档转换为java对象报错:类的两个属性具有相同名称com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsExc...
- Green.AgileMapper新增-Green.ObjectPickUper(do到dto对象的默认抽取)
- DDD中的值对象如何用NHibernate进行映射
- Scala 类和对象详解
- 关于new、Create、对象以及窗口的一点问题
- 集合类操作:未将对象引用设置到对象的实例
- Word中将文本框、图形对象中的文本边距调整
- 浏览器对象属性 window.innerWidth 和 window.outerWidth 这两个宽度属性有何区别?
- List 集合去重合并 , 多种方法演示___关于两个List集合对象去重
- VB编程:获取对象私有域的地址-39_彭世瑜_新浪博客
- Objective-C之成魔之路【7-类、对象和方法】