javascript 连接方式复选框和单选按钮

bxgwgixi  于 2023-01-04  发布在  Java
关注(0)|答案(1)|浏览(125)
Male <input value="V1" checked="checked" name="R1" type="radio">
Female: <input name="R1" value="V2" type="radio"></p>

<input name="C1" value="ON" type="checkbox">Reading 
<input name="C2" value="ON" type="checkbox">Dressing 
<input name="C3" value="ON" type="checkbox">Make up
<input name="C4" value="ON" type="checkbox">Playing

请考虑以下情况:
这里男性单选按钮被选中。我想复选框阅读和播放应该被自动选中〈默认或〉
假设女性检查-化妆和穿衣
我想自动检查。

46qrfjad

46qrfjad1#

function select_radio(val){
      if (val=="male"){
    document.getElementById("C1").checked = true;
    document.getElementById("C2").checked = true;
    document.getElementById("C3").checked = false;
    document.getElementById("C4").checked = false;
      }
      else{
    document.getElementById("C3").checked = true;
    document.getElementById("C4").checked = true;
    document.getElementById("C1").checked = false;
    document.getElementById("C2").checked = false;
      }


    }

Male <input value="V1" checked="checked" name="R1" type="radio" onclick="select_radio('male')">
Female: <input name="R1" value="V2" type="radio" onclick="select_radio('female')">></p>

<input name="C1" id="C1"  value="ON" type="checkbox">Reading 
<input name="C2" id="C2"  value="ON" type="checkbox">Dressing 
<input name="C3" id="C3" type="checkbox">Make up
<input name="C4" id="C4" type="checkbox">Playing

相关问题