定義和用法
target 事件屬性可返回事件的目標節點(觸發該事件的節點),如生成事件的元素、文檔或窗口。
event.target
實例
下面的例子可獲得觸發事件的元素:
<html> <head> <script type="text/javascript"> function getEventTrigger(event) { x=event.target; alert("The id of the triggered element: " + x.id); } </script> </head> <body > <p id="p1" onmousedown="getEventTrigger(event)"> Click on this paragraph. An alert box will show which element triggered the event.</p> </body> </html>
結果:
p1