触发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());


  • 2020-12-08 17:23:36

    Window下完全卸载删除Nodejs

    1.从卸载程序卸载程序和功能。 2.重新启动(或者您可能会从任务管理器中杀死所有与节点相关的进程)。 3.寻找这些文件夹并删除它们(及其内容)(如果还有)。根据您安装的版本,UAC设置和CPU架构,这些可能或可能不存在:

  • 2020-12-09 08:48:45

    nodejs版本以及其对应的npm版本

    正在寻找某个大版本的最新版? Node.js 10.x Node.js 8.x Node.js 6.x Node.js 4.x Node.js 0.12.x Node.js 0.10.x 所有版本

  • 2020-12-12 17:27:54

    手把手教你 GitLab 的安装及使用

    GitLab:是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。

  • 2020-12-12 17:43:33

    linux docker部署gitlab-ce

    首先需要从docker镜像仓库当中获取gitlab-ce的最新镜像文件,由于我本机已经获取了该镜像,所以在此获取的时候会给如下提示。