2014-10-22 49 views
-1

我想在选中选中时禁用复选框。 谢谢如何把复选框禁用?

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

同样喜欢这样的问题[http://stackoverflow.com/questions/2330209/jquery-checkbox-enable-disable]( http://stackoverflow.com/questions/2330209/jquery-checkbox-enable-disable) – 2014-10-22 09:36:35

+0

@ryannghiem这不是一个重复的问题,因为该问题是专门寻找一个jQuery解决方案 – 2014-10-22 09:38:37

+0

如果你问一个关于JavaScript的问题,请post * HTML *,而不是生成该HTML的PHP​​脚本。 – 2014-10-22 09:39:08

回答

1

我认为你不想禁用,但取消选中另一个被点击时的复选框,对不对?

您可以在每个输入一个onclick处理程序做到这一点:http://jsbin.com/dunohofusi/edit

或(这是很容易),你从“复选框”类型更改为“单选”,浏览器会为你做的一切。

如果你想的复选框,看看你可以使用CSS来改变这一回:http://jsbin.com/yodoridadu/edit

+0

感谢它对我来说非常完美:http://jsbin.com/dunohofusi/edit – Boom 2014-10-22 10:37:25

2

如何把复选框中禁用?

简单

HTML

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

JS

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

JQUERY

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

谢谢,虽然有可能吗? – Boom 2014-10-22 09:53:12

+0

虽然?如果你的意思是一段时间循环,那么为什么不呢。只需在循环中提供正确的编号 – 2014-10-22 09:58:30

2

如果您只想要一个答案是可能的,请使用单选按钮。

<input type="radio" />