触发onclick事件元素的获取

2020-03-01 19:00:46

onclick触发元素获取

  • 自动生成元素的onclick事件

  • event.target返回触发事件的元素

  • event.currentTarget返回绑定事件的元素


<script>
var span3=$('<span onclick=delLable("'+data[i]._id+'")></span>');
span3.addClass('num');
span3.html('<i class="Hui-iconfont">&#xe609;</i>');

function delLable(){
	var that=event.currentTarget;
    console.log($(that));
    console.log(event.target);
   
    console.log(event.target.nodeName  )  //获取事件触发元素标签name 
	console.log(event.target.className )   //获取事件触发元素classname
	console.log(event.target.innerHTML)    //获取事件触发元素的内容
	console.log(event.target.id) //获取事件触发元素id
    
    console.log(event.currentTarget.nodeName  )  //获取事件绑定元素标签name 
	console.log(event.currentTarget.className )   //获取事件绑定元素classname
	console.log(event.currentTarget.innerHTML)    //获取事件绑定元素的内容
	console.log(event.currentTarget.id) //获取事件绑定元素id
}
</script>


  • 获取触发onclick元素的父元素 “$“获取元素

console.log($(event.currentTarget).parent());


  • 2018-03-05 11:30:04

    iOS wkwebkit 播放HTML5 视频 全屏问题解决

    使用html5 的video标签播放视频的时候,限制视频的尺寸,在android上是没有问题的,但是在ios上发现,视频没有开始播放的时候还是好的,但是一旦播放开是,就会全屏,非常奇怪。

  • 2018-03-07 14:35:32

    centos7下yum安装ffmpeg

    安装EPEL Release,因为安装需要使用其他的repo源,所以需要EPEL支持 yum install -y epel-release

  • 2018-03-08 09:44:12

    前端性能监控:window.performance

    Web Performance API允许网页访问某些函数来测量网页和Web应用程序的性能,包括 Navigation Timing API和高分辨率时间数据。

  • 2018-03-08 09:44:15

    前端性能监控:window.performance

    Web Performance API允许网页访问某些函数来测量网页和Web应用程序的性能,包括 Navigation Timing API和高分辨率时间数据。

  • 2018-03-08 09:47:14

    ES6,Array.fill()函数的用法

    ES6为Array增加了fill()函数,使用制定的元素填充数组,其实就是用默认内容初始化数组。

  • 2018-03-08 09:53:39

    document.readyState

    一个document 的 Document.readyState 属性描述了文档的加载状态。

  • 2018-03-09 02:09:23

    ArrayBuffer:类型化数组

    ArrayBuffer对象、TypedArray对象、DataView对象是JavaScript操作二进制数据的一个接口。这些对象早就存在,属于独立的规格,ES6将它们纳入了ECMAScript规格,并且增加了新的方法。

  • 2018-03-09 11:45:11

    SQL SELECT DISTINCT 语句

    如需从 Company" 列中仅选取唯一不同的值,我们需要使用 SELECT DISTINCT 语句: