看板 Ajax 關於我們 聯絡資訊
: function CreatTable(){ : for( var i=0;i<sizeArray[1];i++) { : tr = bomBody.insertRow(bomBody.rows.length); : for( var j=0;j<sizeArray[0];j++) { : td = tr.insertCell(tr.cells.length); : td.id=('x'+j+'y'+i); : td.innerHTML = ' '; : if ( td.addEventListener ) : td.addEventListener("mousedown", SetBom, false); : else : td.setAttribute("onmousedown", SetBom); : } } } : function SetBom(onevent) { : var onevent = onevent || window.event; : var onLeftButton=0 , onRightButton=2 , : onMouseButton = onevent.button; : //alert(onMouseButton); : if ( onMouseButton == onLeftButton ) : onLeft(this.id); : else if( onMouseButton == onRightButton) : onRight(this.id); : } 小弟本來先寫其他功能、寫完回來看發現...只要把 td.setAttribute("onmousedown", SetBom); 改成 td.attachEvent("onmousedown", SetBom); 就可以了 但是現在又有一個問題就是 在 SetBom(onevent) 收不到傳過來的 id 不知道是哪裡用錯了...還是 IE 不支援這種寫法呢? 如果是 該如何改呢? -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.160.239.183 ※ 編輯: kiey 來自: 1.160.239.183 (11/10 11:43) ※ 編輯: kiey 來自: 1.160.239.183 (11/10 11:44)
kiey:似乎可以用這種寫法 11/10 12:48
kiey:td.attachEvent("onmousedown", function(){SetBom(this);}) 11/10 12:48
kiey:那 請問我 SetBom(this) this 該打什麼呢>"<? 11/10 12:48
kiey:我試了 this.event 可以抓到 左右鍵 可是抓不到 id 11/10 13:54
sk1765: var el = onevent.target || onevent.srcElement; 11/10 15:55
sk1765:onLeft(el); onRight(el); 11/10 15:57
sk1765:另外 微軟的左鍵是 1不是0 所以你的程式在IE左鍵也不會動 11/10 16:00
sk1765:上面第二行是 onLeft(el.id); onRight(el.id); 11/10 16:01
kiey:太感謝 sk1765 大了...這問題困擾我一天了....感激... 11/10 16:09