Jquery checkbox里面的div检查了一个时间 [英] Jquery checkbox inside div checked one at time

查看:98
本文介绍了Jquery checkbox里面的div检查了一个时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个div,自动生成和内部有3个复选框与不同的ID&名称,默认情况下,它们都不检查!如果一个碰巧得到检查,然后我需要其他两个未选中!

So i have a div thats auto generated and inside are 3 check boxes with different id's & names and by default none of them are checked!! If one happens to get checked then i need the other two unchecked!!

因此一次只能检查一个...

So only one can be checked at a time ...

所有未选中或只有一个选中!

So all unchecked or only one checked!

<div class="configoptions">
    <table class="configtable" cellpadding="0" cellspacing="0" width="100%">
        <tbody>
            <tr>
                <td class="fieldlabel">Include:</td>
                <td class="fieldarea">
                    <label><input name="configoption[10]" id="co30" value="1" onclick="recalc()" type="checkbox">green</label>
                </td>
            </tr>
            <tr>
                <td class="fieldlabel">Include:</td>
                <td class="fieldarea">
                    <label><input name="configoption[9]" id="co27" value="1" onclick="recalc()" type="checkbox">blue</label>
                </td>
            </tr>
            <tr>
                <td class="fieldlabel">Include:</td>
                <td class="fieldarea">
                    <label><input name="configoption[11]" id="co31" value="1" onclick="recalc()" type="checkbox">white</label>
                </td>
            </tr>
        </tbody>
    </table>
</div>

这里是我用来取消选中页面上的所有divs ..因为最初我需要他们取消选中。 。工作伟大...现在我需要使它只有一个是检查,如果它检查!有人可以给一只手吗?

Here is what i used to uncheck all divs on page ready.. since initially i need them unchecked.. that works great... now i need to make it so only one is check at a time if it is checked! Can someone gimme a hand,? Thx in advance!

$(document).ready(function() {
    $('input[type=checkbox]').each(function() {
        this.checked = false;
    });
});


推荐答案

使用 code>函数更改checkbox和单选按钮的checked属性

Use the prop function to change the checked property of checkbox and radio buttons

$(function(){
    $('input:checkbox').prop('checked', false)
    $('input:checkbox').click(function(){
        if($(this).is(':checked')){
            $('input:checkbox').not(this).prop('checked', false);        
        }
    });
})

演示:小提琴

这篇关于Jquery checkbox里面的div检查了一个时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆