触发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-01-23 02:22:17

    andorid,把控件置于最顶端。bringToFront的意外发现

     bringToFront方法在SDK中的说明是“Change the view's z order in the tree, so it's on top of other sibling views”,翻译过来就是改变view的z轴,使其处在他父view的顶端。关于bringToFront的实现,网上有很多资料介绍,大体来说就是将这个view从父view中移除,然后再加入父view的顶端。具体实现如何呢?

  • 2018-01-26 01:05:22

    Android在thread中Toast不能显示问题解决

    一般如果不是在主线程中又开启了新线程的话,一般都会碰到这个问题。 原因是在创建新线程的时候默认情况下不会去创建新的MessageQueue。