javascript的各种兼容就是为了解决不同浏览器的差异性,了解其中的差异能够帮助你更快的解决问题,提高代码的使用质量,编写更优秀的javascript代码。 以上两个兼容通常会这么写: 3.添加、去除事件 FF:可用div1.getAttribute("value") IE不可以, IE8以上、chrome、safari、firefox:支持使用window.screenX和window.screenYvar leftX = typeof window.screenLeft == 'number' ? window.screenLeft : window.screenX;ver topY = typeof window.screenTop == 'number' ? window.screenTop : window.screenY; IE系列:document.body.clientWidth和document.body.clientHeightvar width = window.innerWidth;var height = window.innerHeight;if(typeof width != 'number'){if(document.compatMode == 'CSS1Compat'){width = document.documentElement.clientWidth;height = document.docuementElement.clientHeight;}else{width = document.body.clientWidth;height = document.body.clientHeight;}
一起学吧部分文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与一起学吧进行文章共享合作。