聚合物1.0点击事件的目标是孩子 [英] Polymer 1.0 on-tap event's target is child

查看:133
本文介绍了聚合物1.0点击事件的目标是孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < div id =parenton-tap = myclickEvent > 
< h1>一些文本< h1>
< / div>

但是当我点击它,触发的事件中的目标属性是h1。
如何更改以使父元素成为目标?

解决方案

尝试 e .currentTarget 。不要指望它在 console.log 中显示,尽管浏览器功能在Chrome中是异步的(实际上甚至不会在事件中记录事件对象或对象)。但是如果您在代码中尝试这样做,您可以看到它实际上返回一个 div

  myclickEvent:function(e){
...
var tag = e.currentTarget.tagName;
console.log(tag);
}


I'm using on-tap to detect element clicks.

<div id="parent" on-tap="myclickEvent">
    <h1>Some text<h1>
</div>

But when i click on it, the target attribute in the fired event is the h1. How do I change to make the parent element be the target?

解决方案

Try e.currentTarget. Don't expect it to be shown in console.log though as that browser function is asynchronous in Chrome (actually don't even bother logging event objects or objects inside events). But you can see it actually returns a div if you try this in your code.

myclickEvent: function(e){
  ...
  var tag = e.currentTarget.tagName;
  console.log(tag);
}

这篇关于聚合物1.0点击事件的目标是孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆