启用禁用复选框但不是全部

问题描述 投票:-1回答:1

我有多个复选框我要禁用其他复选框(即StudentParentFaculty)如果我选择All但如果我选择Student或其他All复选框将仅被禁用

<input type="checkbox" name="scope[]" value="All">ALL</input>
<input type="checkbox" name="scope[]" value="Student">Student</input>
<input type="checkbox" name="scope[]" value="Parent">Parent</input>
<input type="checkbox" name="scope[]" value="Faculty">Faculty</input>
<input type="checkbox" name="scope[]" value="Others">Others</input>
javascript html
1个回答
0
投票

您可以使用相同的名称但不同的ID来禁用您的复选框

<input type="checkbox" name="scope[]" value="All" id="all">ALL</input>
<input type="checkbox" name="scope[]" value="Student" id="student">Student</input>
<input type="checkbox" name="scope[]" value="Parent" id="Parent">Parent</input>
<input type="checkbox" name="scope[]" value="Faculty" id="Faculty">Faculty</input>
<input type="checkbox" name="scope[]" value="Others" id="others">Others</input>

并且您可以使用JavaScript来禁用复选框。

document.getElementById("others").disabled = true;
© www.soinside.com 2019 - 2024. All rights reserved.