【问题标题】:JavaScript queryselector method not working in IE8JavaScript 查询选择器方法在 IE8 中不起作用
【发布时间】:2015-05-11 06:54:10
【问题描述】:

以下代码在 Chrome 中运行,但在 IE 中不运行

repNumObject    = document.querySelector("input[type='radio']:checked");

在 try catch 块中抛出无效参数错误 请提出解决方案

【问题讨论】:

  • 您的页面是否有正确的 DOCTYPE 声明?
  • IE8 仅部分支持 (caniuse.com/#feat=queryselector),但您可能应该放弃对 IE8 的支持,因为 Windows XP 已正式死去,而 IE8 紧随其后。
  • @DasDas 它有适当的 DTD 并且在 Chrome 和 IE 9+ 中工作,我需要它在 IE8 中工作

标签: javascript html ie8-compatibility-mode


【解决方案1】:

我认为问题出在:checked selector,即not supported in IE8

var els = document.querySelectorAll("input[type='radio']");
//need to loop els and find the checked item
for (var i = 0; i < els.length; i++) {
    if (els[i].checked) {
        repNumObject = els[i];
    }
}

【讨论】:

  • 感谢帮助它适用于所有浏览器,这是我正在寻找的确切答案
【解决方案2】:

IE8 中的document.querySelector 只识别CSS 2.1 选择器和非特殊标签(html5 标签,如section 或article)。 为尽快避免这种情况,您可以使用 jQuery 之类的库:http://jquery.com/

【讨论】:

  • 这是真的,但我不能使用 JQ,因为它正在部署的平台
猜你喜欢
  • 2013-03-08
  • 1970-01-01
  • 2012-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-18
相关资源
最近更新 更多