jquery中this和event.target的区别

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>this和event.target的区别</title>
<script type="text/javascript" src="js/jquery.min.js" ></script>
</head>
<body>
<script type="text/javascript">
$(function(){
$("li").click(function(e){
alert("下面是li的");
alert($(this).html());
alert($(e.target).html());
});
$("ul").click(function(e){
alert("下面是ul的");
alert($(this).html());
alert($(e.target).html());//最原始触发事件冒泡的位置的
});

})
// 1.this和event.target的区别:
//
// js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事件的目标DOM元素;
//
// 2.this和event.target都是dom对象,如果要使用jquey中的方法可以将他们转换为jquery对象:$(this)和$(event.target);
</script>
<div>
<ul>
<li>你好</li>
</ul>
</div>
</body>
</html>

时间: 2024-08-02 15:14:16

jquery中this和event.target的区别的相关文章

【Jquery】this和event.target的区别

1.js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事件的目标DOM元素: 2.this和event.target都是dom对象,如果要使用jquey中的方法可以将他们转换为jquery对象:$(this)和$(event.target); ex: js代码 1 $(function(){ 2 $("li").live("click",function(event){ 3 $("#temp").

jquery 中 on 和普通绑定的区别

都说on是用于动态添加的元素的事件.但是你不觉得奇怪嘛,难道动态添加的元素就不能用普通的事件绑定,这样说不通啊! 其实是on可以在元素添加到dom之前绑定,而对于普通绑定,只要元素已经出现在了dom中,不论是否动态添加  事件当然也是生效的 $('body').on('click', '.d1', function(event) { //event.preventDefault(); console.log('on0');//ok }); console.log($('.d1')); $('.d

event.currentTarget与event.target的区别介绍

event.currentTarget与event.target的区别想大家在使用的时候不是很在意,本文以测试代码来讲解它门之间的不同.即,event.currentTarget指向事件所绑定的元素,而event.target始终指向事件发生时的元素.翻译的不专业,好拗口啊,还是直接上测试代码吧: <div id="wrapper"> <a href="#" id="inner">click here!</a>

jquery中html 与 text方法的区别

jquery中html 与 text方法的区别 24 May 2012/in 网站设计和开发 /by Bruce 接鉵jquery的时间并不长,以前都是用直接用js写的,现在发现在jquery这个框架用起来很方便,不但代码量少了,使用也比较简单,对于浏览器的兼容问题也不用担心,在使用的过程中也会遇到一些疑问,在html标签中附加子标签时所用的方法html()与text()的区别. 通常在用jquery写ajax时,都会用到html()这个方法,而不用text()这个方法,他们之间有什么区别呢?

jQuery中的bind() live() delegate()之间区别分析

jQuery中的bind() live() delegate()之间区别分析 首先,你得要了解我们的事件冒泡(事件传播)的概念,我先看一张图 1.bind方式 $('a').bind('click',function (){ alert('click'); }) 解析:这种方式最简单,jq扫描文档找出所有的a,让将函数绑定到每个元素的click事件上 2.live方式 $('a').live('click',function (){ alert('click'); }) 解析:jq将函数绑定到$

jQuery中的closest()和parents()的区别

jQuery中的closest()和parents()的区别 jQuery中closest()和parents()的作用非常相似,都是向上寻找符合选择器条件的元素,但是他们之间有一些细微的差别,官网也给出了说明: .closest() .parents() Begins with the current element Begins with the parent element Travels up the DOM tree until it finds a match for the sup

jQuery中 .bind() .live(). delegate() . on() 的区别

jQuery中   .bind()    .live().   delegate() .   on()  的区别 这几种方法都是绑定事件用到的,但是他们之间有些差别 bind(type,[data],fn) 为每个匹配元素的特定事件绑定事件处理函数 例如: <ul> <a href="#"><li>1111111</li></a> <a href="#"><li>22222</

jQuery 中的children()和 find() 的区别

<!DOCTYPE html> <html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> </head> <body> <ul class="level-1"> <li class="item-i">I</li>

jquery中this与$(this)的用法区别

jquery中this与$(this)的用法区别.先看以下代码: $("#textbox").hover( function() { this.title = "Test"; }, fucntion() { this.title = "OK”; } ); 这里的this其实是一个Html 元素(textbox),textbox有text属性,所以这样写是完全没有什么问题的. 但是如果将this换成$(this)就不是那回事了,就会报错了. 以下写法是错误的