當前位置:編程學習大全網 - 行動軟體 - javascript中window.event.srcElement.id的意思

javascript中window.event.srcElement.id的意思

這段代碼只能在ie下工作,其他瀏覽器可能沒有window.event對象。

window.event表示當前觸發的事件對象。window.event.srcElement表示觸發事件的DOM元素。如果妳點擊了按鈕1,這個srcElement就是按鈕1。id就是這個元素的id,即btn1。

如果想要在其他瀏覽器中使用,妳需要把對象傳入函數,即:

<button?id="btn1"onclick="aaa(this)"?>?按鈕1?</button>

<button?id="btn2"onclick="aaa(this)"?>?按鈕2?</button>

<button?id="btn3"onclick="aaa(this)"?>?按鈕3?</button>

<button?id="btn4"onclick="aaa(this)"?>?按鈕4?</button>

<button?id="btn5"?onclick="aaa(this)">?按鈕?5</button>

<scripttype="text/javascript">

function?aaa(elem)

{

alert(elem.id);

}

</script>

望采納!

  • 上一篇:奧妮克希亞的巢穴需要做哪些任務才可以進去
  • 下一篇:玻璃門上老化的即時貼怎麽去掉
  • copyright 2024編程學習大全網