首页题目详情
以下哪项代码是正确使用事件对象的示例?

A.element.onclick = function() { console.log(event.target); }
B.element.addEventListener('click', function() { console.log(event.type); })
C.element.onmouseover = function(event) { console.log(event.srcElement); }
D.以上所有选项都正确。
优质解答
答案
D
解析
所有选项都展示了正确使用事件对象的方式。A使用了onclick事件的默认处理方式,B使用了addEventListener绑定,C使用了onmouseover并传递了event对象。因此D选项正确。
Web程序设计单选题中等AI生成