IE6/7/8/9/10/Opera:设置成功(Opera是个怪胎,styleFloat和cssFloat都支持) Firefox/Safari/Chrome:设置不成功 因此,使用css方法获取或设置浮动时为避免各浏览器差异还是老老实实的使用float。不要使用styleFloat或cssFloat。 当然如果这算jQuery的bug,那么修复也是很容易的 1,修改jQuery.css方法,加个styleFloat的判断。 复制代码 代码如下: // cssFloat needs a special treatment if ( name === "cssFloat" || name === "styleFloat") { name = "float"; }
这样使用$(xx).css("styleFloat") 就没有兼容性问题了。 2,修改jQuery.style方法,加个判断如果传styleFloat或cssFloat都转成float 复制代码 代码如下: // Don"t set styles on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { return; } // 这是加的修复代码 if( name === "cssFloat" || name === "styleFloat" ) { name = "float" } // Make sure that we"re working with the right name var ret, type, origName = jQuery.camelCase( name ), style = elem.style, hooks = jQuery.cssHooks[ origName ];