如何使用jQuery编写IE属性Hacks?

时间:2011-11-17 08:09:37

标签: jquery internet-explorer properties

我正在为跨浏览器视图效果编写jQuery动画。我需要使用hack属性_height*height来处理IE。我尝试用

设置属性
$('#notice_container').css({'_margin-bottom':'auto', 'margin-bottom': '31px'});

但它没有设置_margin-bottom,因为我已指定通过margin-bottom设置。

那么,我的问题是如何用jQuery设置那些IE指定的属性?

3 个答案:

答案 0 :(得分:2)

为什么你可以尝试

if( $.browser.msie && $.browser.version == 7.0 )
{
    $('#notice_container').css({'margin-bottom':'auto'});
}

答案 1 :(得分:2)

虽然不能直接回答如何使用jQuery实现传统的IE CSS攻击,但您可能会对这里概述的更清晰的解决方案感兴趣:

http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

基本上,您使用条件注释将类分配给html元素,具体取决于正在运行的IE版本:

<!--[if lt IE 7]>      <html class="ie6"> <![endif]-->
<!--[if IE 7]>         <html class="ie7"> <![endif]-->
<!--[if IE 8]>         <html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html>         <!--<![endif]-->

然后像这样定位元素而不是使用黑客:

$('.ie7 #notice_container').css({'margin-bottom':'auto'});

如果需要,可以选择ID或不同的类名。这是一种非常干净的“黑客攻击”IE的方法。

答案 2 :(得分:0)

您可以尝试直接设置样式属性:

 .attr({'style':'_margin-bottom:auto;margin-bottom:31px'});
相关问题