js基础 - 兼容代码
js基础 - 兼容代码
1. scrollTop 1. chrome document.body.scrollTop 2. IE && firefox document.documentElement.scrollTop 2. 阻止事件默认行为 1. 绑定事件 1. 主流浏览器 e.preventDefault(); 2. 低版本 IE e.returnValue = false; 2. 没有绑定事件 return false; 3. 事件绑定 1. 主流浏览器 obj.addEventListener(‘click‘, function () {}, false); PS: false > 事件冒泡 true > 事件捕获 2. 低版本 IE obj.attachEvent(‘onclick‘, function () {}); PS: function () {return this} this === window 4. JS 拖拽时 选中文字 1. 主流浏览器 return false; 2. 低版本 IE 1. 捕获 obj.setCapture() 2. 释放 obj.releaseCapture();