Internet Explorer中的JavaScript NaN错误 [英] JavaScript NaN error in Internet Explorer

查看:105
本文介绍了Internet Explorer中的JavaScript NaN错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带单选按钮的表单:

I have a form with radio buttons:

<ul class='likert'>
  <li>
    <input type="radio" name="q1" value=5 required>
  </li>
  <li>
    <input type="radio" name="q1" value=4>
  </li>
  <li>
    <input type="radio" name="q1" value=3 checked="checked">
  </li>
  <li>
    <input type="radio" name="q1" value=2>
  </li>
  <li>
    <input type="radio" name="q1" value=1>
  </li>
</ul>

在Firefox和Chrome中,

In Firefox and Chrome,

parseInt(document.forms["question_form"]["q1"].value)

返回3(或其他),但在Internet Explorer中我得到'NaN'。

returns 3 (or whatever) but in Internet Explorer I get ‘NaN’.

(道歉,如果我问这个错误,我是新的这里...)

(Apologies if I'm asking this wrong, I'm new here...)

推荐答案

当名称在 document.forms中不唯一时,IE会返回一个HTMLCollection [question_form] [q1]

请参阅IHTMLElementCollection




如果找到重复名称,则会返回这些具名项目的集合。 >你可以像这样得到检查值:

You can get the checked value for example like this:

var val = document.querySelector('.likert input:checked').value);

这篇关于Internet Explorer中的JavaScript NaN错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆