【问题标题】:Combine IE hacks with JQuery css()?将 IE hack 与 JQuery css() 结合起来?
【发布时间】:2013-12-12 13:27:25
【问题描述】:

我需要为 IE 7 调整元素高度。通常我会在我的外部样式表中使用 hack \9 来执行此操作,例如:

#container {
 height: 200px\9;
}

但是这个特定的高度是由 JQuery 生成的,例如:

$('#container').css({'height': containerheight});

对于 IE,我需要添加 hack,所以我尝试了:

var iecontainerheight = height + 'px\9;';
$('#container').css({'height': iecontainerheight});

但这不起作用。

有谁知道如何正确地使用 css() 包含该 hack?

【问题讨论】:

  • 如果你想使用脚本改变高度为什么不做浏览器检测然后分配正确的高度
  • \9 是做什么的?我在 IE7 中从来没有遇到过高度问题

标签: javascript jquery css internet-explorer cross-browser


【解决方案1】:

您应该从 'px\9;' 中删除 ;。无效。

也可以试试这个:

var iecontainerheight = height + '\9';
$('#container').css({'height': iecontainerheight});

【讨论】:

    【解决方案2】:

    您也可以尝试使用 jQuery 检测浏览器。仅适用于IE浏览器。

    if (m_BrowserName == "Microsoft Internet Explorer" && m_BrowserVersion.indexOf("MSIE 7.0") > 0){
          //your css goes here    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-22
      • 2011-11-01
      • 2014-06-15
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      相关资源
      最近更新 更多