触发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-21 09:42:42

    iframe.contentWindow 操作iframe

    注:iframe.contentWindow这里,返回的是iframe的window对象,所以后面可以接着调用document方法,再接着调用getElementByTagName。那么就可以对iframe里面的元素进行操作了。

  • 2020-12-21 14:00:19

    iframe + postMessage跨域通信

    在实际项目开发中可能会碰到在 a.com 页面中嵌套 b.com 页面,这时第一反应是使用 iframe,但是产品又提出在 a.com 中操作,b.com 中进行显示,或者相反。

  • 2020-12-22 12:02:41

    ios开发优秀的开源框架,demo集合

    期待大家和我们一起共同维护,同时也期望大家随时能提出宝贵的意见(直接提交issues即可)。请广大网友只按照目录结构(即使目录结构有问题)添加三方库,并提交pull request。目录问题大家提出issues后楼主会及时更改的。