简体   繁体   English

如何使复选框处于禁用状态?

[英]how to put checkbox in disabled?

I'd like to disable the checkbox when an election is checked. 我想在选中选举后禁用此复选框。 Thank you 谢谢

<form id="tform" method="post">
    Sélectionnez le type de la machine :<br>
    <input  type="checkbox" id="1" name="g"<?php if ($_POST['g'] == "pc") {echo  'checked="checked"';} ?> value="pc" class="checkbox"> Pc
    <input  type="checkbox" id="2" name="g"<?php if ($_POST['g'] == "wiiu") {echo 'checked="checked"';} ?> value="wiiu" class="checkbox">Wii U
    <input  type="checkbox" id="3" name="g"<?php if ($_POST['g'] == "xbox-360") {echo 'checked="checked"';} ?> value="xbox-360" class="checkbox">Xbox-360
    <input  type="checkbox" id="4" name="g"<?php if ($_POST['g'] == "playstation-4-ps4") {echo 'checked="checked"';} ?> value="playstation-4-ps4" class="checkbox">Ps4
    <input  type="checkbox" id="5" name="g"<?php if ($_POST['g'] == "playstation-3-ps3") {echo 'checked="checked"';} ?> value="playstation-3-ps3" class="checkbox">Ps3<br>
    <input  type="checkbox" id="6" name="g"<?php if ($_POST['g'] == "xbox-one") {echo 'checked="checked"';} ?> value="xbox-one" class="checkbox">One
    <input  type="checkbox" id="7" name="g"<?php if ($_POST['g'] == "nintendo-3ds") {echo 'checked="checked"';} ?> value="nintendo-3ds" class="checkbox">3ds
    <input  type="checkbox" id="8" name="g"<?php if ($_POST['g'] == "playstation-vita") {echo 'checked="checked"';} ?> value="playstation-vita" class="checkbox">Vita
    <input  type="checkbox" id="9" name="g"<?php if ($_POST['g'] == "iphone-ipod") {echo 'checked="checked"';} ?> value="iphone-ipod" class="checkbox">Iphone
    <input  type="checkbox" id="10" name="g"<?php if ($_POST['g'] == "android") {echo 'checked="checked"';} ?> value="android" class="checkbox">Anfroïd
    </form>

how to put checkbox in disabled? 如何使复选框处于禁用状态?

Simple 简单

HTML 的HTML

<input  type="checkbox" id="test" name="checkBoxName" disabled>

JS JS

document.getElementById("checkBoxID").disabled = true;

JQUERY JQUERY

$("#checkBoxID").prop('disabled', true);

如果您只希望一个答案,请使用单选按钮。

<input type="radio" />

I think you don't want to disable but uncheck the checkbox when another is clicked, am I right? 我想您不想禁用它,但是在单击另一个时取消选中该复选框,对吗?

You can either do this with an onclick handler on each input: http://jsbin.com/dunohofusi/edit 您可以在每个输入上使用onclick处理程序来执行此操作: http : //jsbin.com/dunohofusi/edit

Or (and this is much easier) you change the type from "checkbox" to "radio" and the browser will do everything for you. 或者(这很容易)将类型从“复选框”更改为“无线电”,浏览器将为您做所有事情。

If you want the checkbox-look you can use css to change this back: http://jsbin.com/yodoridadu/edit 如果您希望使用复选框,则可以使用css将其更改为: http : //jsbin.com/yodoridadu/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM