Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 一旦选中某个类,jQuery将禁用该类的复选框_Php_Jquery - Fatal编程技术网

Php 一旦选中某个类,jQuery将禁用该类的复选框

Php 一旦选中某个类,jQuery将禁用该类的复选框,php,jquery,Php,Jquery,因此,我有一些php代码,为阿凡达弹出复选框。然而,该人只能选择其图库中的一个图像作为其化身。但是,当他们选中其中一个框时,我希望能够禁用所有其他框。我似乎无法理解这一点。尝试了很多不同的东西,所以我想我会问具体的代码 echo 'Avatar: <input type="checkbox" name="membersview[]" class="memberavatar" value="'.$galleryid.'" /><br />'; echo'Avatar:;

因此,我有一些php代码,为阿凡达弹出复选框。然而,该人只能选择其图库中的一个图像作为其化身。但是,当他们选中其中一个框时,我希望能够禁用所有其他框。我似乎无法理解这一点。尝试了很多不同的东西,所以我想我会问具体的代码

echo 'Avatar: <input type="checkbox" name="membersview[]" class="memberavatar" value="'.$galleryid.'" /><br />';
echo'Avatar:
所以我想要的是,如果一个用户选中了任何一个复选框,其中包含一类成员化身。我想禁用membersavatar类的其他复选框

一些示例HTML输出,以便您可以看到浏览器是如何重新排序的

<form action="/members/members_gallery.php" method="post" id="memberdetail">
<div style="width:150px; height:200px; float:left; margin:0; padding:0; border:0;">
    <a href="../site/images/gallery/users/ninja@theringersclan.com/1390202957-20130816_193346.jpg" target="_blank">
        <img src="../site/images/gallery/users/ninja@theringersclan.com/1390202957-20130816_193346.jpg" style="width:150px; height:150px; margin:0; border:0; padding:0;">
    </a> 
    <br>Is Public: <input type="checkbox" name="galleryid[]" value="5">
    <br>Members: <input type="checkbox" name="membersview[]" value="5" checked="checked">
    <br>Avatar: <input type="checkbox" name="membersview[]" class="memberavatar" value="5">
    <br>Delete: <input type="checkbox" name="deletepic[]" value="5">
    <br>
</div>
<div style="width:150px; height:200px; float:left; margin:0; padding:0; border:0;">
    <a href="../site/images/gallery/users/ninja@theringersclan.com/1390203939-240_screenshots_2014-01-19_00001.jpg" target="_blank">
        <img src="../site/images/gallery/users/ninja@theringersclan.com/1390203939-240_screenshots_2014-01-19_00001.jpg" style="width:150px; height:150px; margin:0; border:0; padding:0;">
    </a>
    <br>Is Public: <input type="checkbox" name="galleryid[]" value="7" checked="checked">
    <br>Members: <input type="checkbox" name="membersview[]" value="7" checked="checked">
    <br>Avatar: <input type="checkbox" name="membersview[]" class="memberavatar" value="7">
    <br>Delete: <input type="checkbox" name="deletepic[]" value="7"><br></div><div class="cl">
</div>
<br><br>
<input type="submit" name="galleryupdatepics" value="Update Pics" style="float:left">


公众:
成员:
化身:
删除:

公众:
成员:
化身:
删除:


类似这样的东西-

$function(){
    $('.memberavatar').click(function(){
          $('.memberavatar').not(this).each(function(){
              $(this).prop("disabled", true);
          });
    });
});
$(function(){
    $('.memberavatar').click(function(){
        if($(this).is(':checked')){
              $('.memberavatar').not(this).each(function(){
                  $(this).prop("disabled", true);
              });
        }
        else {
              $('.memberavatar').prop("disabled", false);
        }
    });
});
JSFIDLE示例-


更新
要模拟一个放射组,但仅在“未选中”第一个组之后,请尝试以下操作-

$function(){
    $('.memberavatar').click(function(){
          $('.memberavatar').not(this).each(function(){
              $(this).prop("disabled", true);
          });
    });
});
$(function(){
    $('.memberavatar').click(function(){
        if($(this).is(':checked')){
              $('.memberavatar').not(this).each(function(){
                  $(this).prop("disabled", true);
              });
        }
        else {
              $('.memberavatar').prop("disabled", false);
        }
    });
});

jshiddle-

大致如下:

$('.memberavatar').click(function(event) {
    $('.memberavatar').prop('disabled', true);
    $(event.target).prop('checked',true);
});
小提琴:


当然,在这种情况下,使用单选按钮而不是复选框更有意义,这将非常有效

代码:

$("input:checkbox.memberavatar").click(function () {
    $(':checkbox').not($(this)).attr('checked', false);
});
jsIDLE:

您可以这样做:

$(function(){
    $('.memberavatar').click(function(){
    $('.memberavatar').not(this).each(function(){
    $(this).attr('checked', false);
    });

});

但正如有人告诉你的那样,你最好使用单选按钮。上面的函数简单地把某个类的复选框表示为单选按钮。

你所问的更像是“单选按钮”的操作,所以我建议你考虑使用更自然的控件来进行这种操作。这是最接近的。但是,如果取消选中,则不会将其余部分切换为启用状态。你能帮我写一个快速的if语句来帮助切换吗?我已经更新了检查
是否(':checked')
,如果没有删除“disabled”属性。谢谢先生。这很有效感谢大家的建议,并抽出时间帮助他人:)我百分之百同意。但是我别无选择,我的老板喜欢复选框的外观。因此。。猴子照老板说的做哈,你确定要禁用所有其他复选框而不是取消选中吗?要添加到此答案,您需要添加逻辑,以便在取消选中选中的答案时重新启用所有其他答案。