var button = document.getElementById("buttonId"); if(button.addEventListener){ button.addEventListener("click",eventFunction,false); }else if(button.attachEvent){ button.attachEvent("onclick",eventFunction); }
二、屬性:
javascript
altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y |
//IE:有window.event對象 //FF:沒有window.event對象。能夠經過給函數的參數傳遞event對象。如onmousemove=doMouseMove(event) <script> function test(event) { var event = event || window.event; //do Something } </script> <input type="button" value="click" onclick="test(event)"/>