一组radio ,首先给一个radio设checked=true之后,当在选择其他的radio,会出现两个checked=true的情况,这样改怎么解决呢??

解决方案 »

  1.   

    单项选择控件是按name属性值分组的,很显然,你的几个单选控件的name属性值不同。
      

  2.   


    <div id="lightBox_content" style="display:none;">
    <div id="operChd" style="text-align:left;padding: 0 0 0 30px;">
    <input type="radio" name="chdType" value="asd" >
    <span style='width:110;display:inline-block;text-align:left;'>房间隔缺损介入封堵治疗手术</span><br>
    <input type="radio" name="chdType" value="ps">
    <span style='width:110;display:inline-block;text-align:left;'>肺动脉瓣狭窄球囊成形术手术</span><br>
    <input type="radio" name="chdType" value="pda">
    <span style='width:110;display:inline-block;text-align:left;'>动脉导管未闭介入封堵治疗手术</span><br>
    <input type="radio" name="chdType" value="vsd">
    <span style='width:110;display:inline-block;text-align:left;'>室间隔缺损介入封堵治疗手术</span><br>
    <input type="radio" name="chdType" value="rasa">
    <span style='width:110;display:inline-block;text-align:left;'>主动脉瘤破裂介入封堵治疗手术</span><br>
    <input type="radio" name="chdType" value="cafc">
    <span style='width:110;display:inline-block;text-align:left;'>冠状动脉瘘介入封堵治疗手术</span><br>
    <input type="radio" name="chdType" value="ms">
    <span style='width:110;display:inline-block;text-align:left;'>二尖瓣狭窄球囊成形术手术</span><br>
    <br>
    </div>
    <a href="javascript:sendResult()"><img src="<%=request.getContextPath()%>/images/button/b_confirm_3.gif" style="cursor:hand;"/></a>&nbsp;
    </div>
    <script>
    function coverDiv(uuidRecord,dateRecord){

    $.post(cp+"/ajaxs/operation/record/query_chd_oper_name.html",{uuid:uuidRecord},function(data){
    if(data!=-1){
    $(":radio").eq(data).attr("checked",true);
    }
    else{
    $(":radio").attr("checked",false);
    }
    var lightBox_content_innerHTML = $("#lightBox_content").html();
    addCover(lightBox_content_innerHTML, null, null, null, '300');
    uuid = uuidRecord;
    date = dateRecord;
    })
    }
    function sendResult(){
    var selectRadio = $("input[type='radio']:checked");
    alert(selectRadio.length)
    var selectRadioVal = selectRadio.val();
    alert(selectRadioVal)
    if(selectRadioVal==undefined){
    alert("请选择先心病手术分类");
    }
    else{
    editInstance(uuid,"/https/operation/record/get_operation_record_create_chd_"+selectRadioVal+"_"+date+".html");
    discover();
    }
    }</script>
      

  3.   

    调用coverDiv后显示的radio,同时默认设置一个radio的checked为true。。
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript1.5" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script language="javascript1.5" type="text/javascript">
    $().ready(function(){
    var data=0;
    if(data!=-1){
                $(":radio").eq(data).attr("checked",true);
            }
            else{
                $(":radio").attr("checked",false);
            }
    });
    </script>
    </head><body>
    <div id="lightBox_content" style="display:">
        <div id="operChd" style="text-align:left;padding: 0 0 0 30px;">
            <input type="radio" name="chdType" value="asd" >
                <span style='width:110;display:inline-block;text-align:left;'>房间隔缺损介入封堵治疗手术</span><br>
            <input type="radio" name="chdType" value="ps">
                <span style='width:110;display:inline-block;text-align:left;'>肺动脉瓣狭窄球囊成形术手术</span><br>
            <input type="radio" name="chdType" value="pda">
                <span style='width:110;display:inline-block;text-align:left;'>动脉导管未闭介入封堵治疗手术</span><br>
            <input type="radio" name="chdType" value="vsd">
                <span style='width:110;display:inline-block;text-align:left;'>室间隔缺损介入封堵治疗手术</span><br>
            <input type="radio" name="chdType" value="rasa">
                <span style='width:110;display:inline-block;text-align:left;'>主动脉瘤破裂介入封堵治疗手术</span><br>
            <input type="radio" name="chdType" value="cafc">
                <span style='width:110;display:inline-block;text-align:left;'>冠状动脉瘘介入封堵治疗手术</span><br>
            <input type="radio" name="chdType" value="ms">
                <span style='width:110;display:inline-block;text-align:left;'>二尖瓣狭窄球囊成形术手术</span><br>
            <br>
        </div>
    </div>
    </body>
    </html>用火狐和IE测试了一下,没有你所说的问题发生
      

  5.   

    我的意思是再设置某一个radio的checked为true后,再选其他的radio,会发生多个checked为true。
      

  6.   

    我的意思是再设置某一个radio的checked为true后,再选其他的radio,会发生多个checked为true,我只希望得到最后选中的radio的值,但是按照我上面的写法,还是会得到之前选中的radio值。
      

  7.   

    我去的,我弄明白了,不是jquery问题,是我的代码的问题,真是要谢谢大家。。