【问题标题】:$(window).height() is not working in IE10$(window).height() 在 IE10 中不起作用
【发布时间】:2013-04-22 12:10:50
【问题描述】:

我想根据窗口大小设置 DIV 的高度,但 $(window).height() 在 IE10 中返回 0,它在 IE8 和 IE9 中工作正常。为什么?

我也写了如下的doctype声明

<!--[if IE]>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`
<![endif]-->

如果我删除“&lt;!--[if IE]&gt;”和“&lt;![endif]--&gt;”,那么它工作正常。为什么?请解释。

【问题讨论】:

  • 你的 DOCTYPE 是什么?
  • jQuery 的 $(window).height() 对 doctype 很敏感。你的是什么?
  • +1 到上面的 cmets。还有你用的是什么版本的jQuery?
  • doctype 是 ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" rel="nofollow" target="_blank">w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • jquery版本为jQuery v1.8.3

标签: javascript jquery internet-explorer-10


【解决方案1】:

正如 Irvin Dominin 所说,jQuery 的 $(window).height() 对 doctype 很敏感。由于不支持 Internet Explorer 10 条件 cmets,并且当浏览器不是 IE 时您没有 doctype - jQuery 的 $(window).height() 中断。

【讨论】:

  • 我正在考虑为所有浏览器提供 Doctype,而不仅仅是 IE。因此删除条件 cmets。 :-)
  • 好主意,你应该总是有一个文档类型。
【解决方案2】:

如果您删除 "&lt;!--[if IE]&gt;" and "&lt;![endif]--&gt;",它会起作用,因为您提到了 if/else for IE,然后其他浏览器无法检测到 DOCTYPE,这是正常需要的,因为 $(window).height() 将不起作用。如果没有定义文档类型。所以请为所有浏览器添加 DOCTYPE,问题可以解决

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 2013-06-03
    • 2013-12-02
    • 2013-11-13
    • 2013-08-29
    相关资源
    最近更新 更多