美文网首页
javascript target事件属性

javascript target事件属性

作者: 兔子不打地鼠打代码 | 来源:发表于2018-03-29 21:00 被阅读17次

1、target 事件属性可以返回触发该事件的节点。
2、语法:event.target
3、一般情况下 target放在函数里, 方便函数获取触发函数的元素的其他属性值,例如

<head>
<script type="text/javascript">
function getEventTrigger(event)
  { 
  x=event.target;  //设置tatget
  alert("The id of the triggered element: "
  + x.id);
  }
</script>

</head>
<body >

<p id="p1" onmousedown="getEventTrigger(event)"> //获取<p>标签的id属性值
Click on this paragraph. An alert box will
show which element triggered the event.</p>

</body>

相关文章

网友评论

      本文标题:javascript target事件属性

      本文链接:https://www.haomeiwen.com/subject/bzuvcftx.html