event.trigger不只是在下面的情况下工作。
js文件:
alert(event.target.getAttribute("name"));html文件:
<div class=" tile tile-big tile-5" id="three" name = "Launch" >
<div><p>Launch Application </p></div>
</div>它给出的是"null",而不是名称。
alert(document.getElementById(this.id).getAttribute("name"));工作得很好。
帮帮我。
提前谢谢。
发布于 2013-11-12 09:43:05
问题是你的目标不是
<div class=" tile tile-big tile-5" id="three" name = "Launch" >但
<p>Launch Application </p>它没有" name“属性,这就是为什么获得null,尝试向其添加name属性的原因,您将得到正确的警告。
尝尝这个
<div class=" tile tile-big tile-5" id="three" name = "Launch" onclick="testAlert(event)">
<div name = "Launch2"><p name = "Launch3">Launch Application </p></div>
</div>
<script>
function testAlert(event)
{
var target = event.target || event.srcElement;
alert(target.getAttribute('name'));
}
</script>你会得到答案的
https://stackoverflow.com/questions/19924845
复制相似问题