定义和用法
target 事件属性可返回事件的目标节点(触发该事件的节点),如生成事件的元素、文档或窗口。
语法
event.target
实例
下面的例子可获得触发事件的元素:
1 <html> 2 <head> 3 4 <script type="text/javascript"> 5 function getEventTrigger(event) 6 { 7 x=event.target; 8 alert("The id of the triggered element: " 9 + x.id); 10 } 11 </script> 12 13 </head> 14 <body > 15 16 <p id="p1" onmousedown="getEventTrigger(event)"> 17 Click on this paragraph. An alert box will 18 show which element triggered the event.</p> 19 20 </body> 21 </html>
时间: 2024-10-06 00:45:09