如何通过addEventListener给onclick创建事件监听并传event参数
在html里可以这样将event作为参数传入:
XML/HTML code? script> function clickme(){ alert(event.clientX); } </script> <div onclick="clickme(event)">Click Me!</div>
请问如何通过addEventListener给onclick创建事件监听并传event参数?
<div id="d1">Click Me!</div> <script type="text/javascript"> function clickme(){ alert(event.clientX); } var oDiv = document.getElementById('d1'); //IE if(oDiv.attachEvent){ oDiv.attachEvent("onclick",clickme); } else if(oDiv.addEventListener){ //FireFox oDiv.addEventListener("click",clickme,true); } </script>
function clickme(e){ var event = e || window.event; alert(event.clientX); }