document.onclick vs window.onclick

The JavaScript Window object is the highest level JavaScript object which corresponds to the web browser window.

最外层的JavaScript对象其对应于web浏览器窗口

The document object is the container for all HTML HEAD and BODY objects associated within the HTML tags of an HTML document. This could correspond to the top-most window, or an iframe within the window.

文档对象是一个HTML文档的HTML标签中相关联的所有HTML头部和身体对象的容器. 这可以对应于最上面的窗口,或在窗口内的iframe

Update

After a quick test there really is no difference between the two. However, as others have said, window.onclick did not work when tested in IE8. So apparently the bottom line is that document.onclick is the preferred choice.

window.onclick 不能在IE8下工作,在低版本中 document.onclick 为首选

原文地址:https://www.cnblogs.com/czhyuwj/p/5916902.html