[問題] js onmousedown只能使用一次

看板Ajax作者 (Kulapikachu)時間13年前 (2011/03/13 17:32), 編輯推噓2(203)
留言5則, 4人參與, 最新討論串1/1
寫了一個點一下滑鼠就可以在螢幕顯示座標的函式 程式長這樣 function mouseDown(theEvent) { var theEvent = theEvent ? theEvent : window.event; var locString = "X = " + theEvent.screenX + " Y = " + theEvent.screenY; document.write(locString); } 但不論我用 document.onclick=mouseDown; 或者 <body onclick="mouseDown();"> 只有點第一下可以正常運作 第二下就毫無反應了 請問這樣是什麼原因造成的? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.205.57

03/13 18:13, , 1F
document.write蓋掉你原本網頁的內容了
03/13 18:13, 1F

03/13 18:44, , 2F
所以document.write會新產生一個DOM嗎? 感謝
03/13 18:44, 2F

03/13 21:29, , 3F
對,請用別的方法,例如appendChild之類的
03/13 21:29, 3F

03/14 14:12, , 4F
嗯嗯 感謝
03/14 14:12, 4F

03/15 19:50, , 5F
對,你把document.write使用alert替換一下就好了.
03/15 19:50, 5F
文章代碼(AID): #1DV8yn8p (Ajax)