【问题标题】:how to put checkbox in disabled?如何将复选框置于禁用状态?
【发布时间】:2014-10-22 09:29:53
【问题描述】:

我想在选中选举时禁用该复选框。 谢谢你

<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>

【问题讨论】:

  • @ryannghiem 这不是一个重复的问题,因为该问题专门寻找 jquery 解决方案
  • 如果您询问有关 JavaScript 的问题,请发布 HTML,而不是生成该 HTML 的 PHP 脚本。
  • 使用数字作为 id 通常是个坏主意。
  • 我没有说“重复”,我只是说问题看起来像那样。所以你应该看到

标签: javascript html checkbox


【解决方案1】:

如何禁用复选框?

简单

HTML

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

JS

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

JQUERY

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

【讨论】:

  • 谢谢,但有可能吗?
  • 同时?如果您的意思是使用while循环,是的,为什么不呢。只需在循环中提供正确的 id
【解决方案2】:

如果您只想得到一个答案,请使用单选按钮。

<input type="radio" />

【讨论】:

    【解决方案3】:

    我认为您不想禁用但在单击另一个复选框时取消选中该复选框,对吗?

    您可以在每个输入上使用 onclick 处理程序来执行此操作:http://jsbin.com/dunohofusi/edit

    或者(这更容易)您将类型从“复选框”更改为“收音机”,浏览器将为您完成所有工作。

    如果您想要复选框外观,您可以使用 css 将其改回:http://jsbin.com/yodoridadu/edit

    【讨论】:

    • 请直接在此页面上发布您的建议。如果这些 jsbin 链接失效,那么您的回答就会变得毫无帮助。
    猜你喜欢
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2016-02-17
    • 2019-05-10
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多