1.判断当前js环境是否为严格模式
//定义并调用一个函数来确定当前脚本运行时是否为严格模式 var strict = (function() { return !this; })();
2.检测一个对象是否是真正的函数对象
function isFunction(x) { return Object. prototype. toString.call(x) === "[object Function]' ; }
3.低版本不兼容e.preventDefault()和e.target
//获取事件对象 var getEvent = function (event) { //标准浏览器返回event, IE下window. event return event || window. event ; } //获取元素! var getTarget = function (event) { var event = getEvent (event) ; //标准浏览器下event.target, IE下event.srcElement return event.target || event.srcElement; } //阻止默认行为 var preventDefault = function (event) { var event = getEvent (event) ; //标准浏览器 if (event.preventDefault) { event.preventDefault () ; // IE浏览器 }else { event. returnValue = false; } }