Javascript 单选按钮验证在IE上不起作用

Javascript 单选按钮验证在IE上不起作用,javascript,jquery,validation,Javascript,Jquery,Validation,我有以下代码来验证问卷表单,如果用户输入了所有必需的答案,则在下一页上发布答案。这段代码在Chrome和除IE(InternetExplore)之外的其他浏览器上都能完美运行。它显示警告消息“回答所有问题”,甚至选择选项所有问题。这件事只发生在IE中。。有人能告诉我为什么会这样吗 <script type="text/javascript"> //---------------Method for validating the Question whole form -------

我有以下代码来验证问卷表单,如果用户输入了所有必需的答案,则在下一页上发布答案。这段代码在Chrome和除IE(InternetExplore)之外的其他浏览器上都能完美运行。它显示警告消息“回答所有问题”,甚至选择选项所有问题。这件事只发生在IE中。。有人能告诉我为什么会这样吗

<script type="text/javascript">

//---------------Method for validating the Question whole form --------------//
function checkRadio(name)
{
  var radio = document.forms.myForm[name];
  for (var option in radio)
  {
    if(radio[option].checked)
    { return true; }
  }
  return false;
}

function ValidateQuestions()
{
  if (checkRadio("question1") && checkRadio("question2") && checkRadio("question3") && checkRadio("question4") && checkRadio("question5") && checkRadio("question6") && checkRadio("question7") && checkRadio("question8") && checkRadio("question9") && checkRadio("question10") && checkRadio("question11") && checkRadio("question12") && checkRadio("question13") && checkRadio("question14") && checkRadio("question15") && checkRadio("question16") && checkRadio("question17") && checkRadio("question18") && checkRadio("question19") && checkRadio("question20") ) 
  { return true; }
  else{ return false; }
}

//-----------------------------------------------------------------------------//

jQuery(document).ready(function($) 
{    
    jQuery('#submitFormC').click(function()
    {
     var str = $("#questionnaireForm").serialize();
     var data = {
                 action: 'myajax-submit',
                 s: str,
                 beforeSend: function(){ 
                    $( "#tab" ).empty();
                    $("#tab").append("<img id='busyImg' src='busy.gif'/>");
                    }
                }; 

        if(ValidateQuestions())
        {
        jQuery.post("thankyou.php?t=<?php echo $sid;?>", data,  function(response) { 
        //alert('Got this from the server: ' + response);
        $( "#tab" ).empty().append( response );
        } );
        }
        else { alert("Answer all questions"); }
     return false;   
    });
});
</script>

//---------------验证问题整个表单的方法--------------//
功能检查收音机(名称)
{
var radio=document.forms.myForm[name];
用于(收音机中的var选项)
{
如果(单选[选项].选中)
{返回true;}
}
返回false;
}
函数ValidateQuestions()
{
if(检查无线电(问题1)和检查无线电(问题2)和检查无线电(问题3)和检查无线电(问题4)和检查无线电(问题5)和检查无线电(问题6)和检查无线电(问题7)和检查无线电(问题8)和检查无线电(问题9)和检查无线电(问题10)和检查无线电(问题11)和检查无线电(问题12)和检查无线电(“问题13”)&&checkRadio(“问题14”)&&checkRadio(“问题15”)&&checkRadio(“问题16”)&&checkRadio(“问题17”)&&checkRadio(“问题18”)&&checkRadio(“问题19”)&&checkRadio(“问题20”))
{返回true;}
else{return false;}
}
//-----------------------------------------------------------------------------//
jQuery(文档).ready(函数($)
{    
jQuery('#submitFormC')。单击(函数()
{
var str=$(“#questionnairorm”).serialize();
风险值数据={
操作:“myajax提交”,
s:str,
beforeSend:function(){
$(“#选项卡”).empty();
$(“#选项卡”)。追加(“”);
}
}; 
if(ValidateQuestions())
{
jQuery.post(“thankyou.php?t=”,数据,函数(响应){
//警报('从服务器获取此信息:'+响应);
$(“#tab”).empty().append(响应);
} );
}
else{alert(“回答所有问题”);}
返回false;
});
});
试试这个:小提琴:


也发布hmtl。是否所有单选按钮都有相同的
名称
?@Ani是的,所有单选按钮都有相同的名称。@Ani正如我在问题细节中提到的,它在chrome和firefox上运行良好。只有在IEpost html中才有这个问题。如果所有问题的单选按钮都有相同的名称,那么你的html是错误的。我的意思是说我有两组f我的问题中的单选按钮我必须检查所有需要2到3分钟的浏览器,所以请稍等片刻我在chrome上检查了此功能。现在我选择了所有选项,并且警告消息在chromeYeah上重复。现在它工作正常,可以告诉我代码有什么问题。我正在使用此函数<代码>函数checkRadio(名称){var radio=document.forms.myForm[name];for(radio中的var选项){if(radio[option].选中){return true;}}}return false;}您能告诉我如何更改此方法以显示用户未选择的答案吗..我的意思是,如果有人错过了第17个问题,我希望显示类似“回答第17个问题”的消息
function checkRadio(name)
{
       if($("input[name='"+ name + "']").is(':checked'))
       { return true; }
        alert("Please select " + name);
        return false;
}