您的当前位置:首页正文

jquery 关于event.target使用的几点说明介绍

2024-11-03 来源:个人技术集锦

event.target
说明:引发事件的DOM元素。

this和event.target的区别
js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事件的目标DOM元素;

this和event.target的相同点
this和event.target都是dom对象,如果要使用jquey中的方法可以将他们转换为jquery对象:$(this)和$(event.target);


<body>
&nbsp; &nbsp; <div id="temp"></div>
&nbsp; &nbsp; <ul class="JQ-content-box" style="padding:20px; background:#FFFFFF">
&nbsp; &nbsp; &nbsp; &nbsp; <li>第一行
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ul>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li>这是公告标题1</li>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li>这是公告标题2</li>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li>这是公告标题3</li>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li>这是公告标题4</li>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ul>
&nbsp; &nbsp; &nbsp; &nbsp; </li>
&nbsp; &nbsp; </ul>
</body>
</html>

Top