简体   繁体   English

如何使用jQuery禁用/启用radcombobox内部的多个复选框?

[英]how to disable/enable multiple checkboxes inside of a radcombobox using jquery?

I have an ItemTemplate which where each item contains a RadComboBox with checkboxes enabled. 我有一个ItemTemplate,其中每个项目都包含一个启用了复选框的RadComboBox。 I need to apply some business logic that will disable or enable checkboxes in the combobox depending on the user's selections. 我需要应用一些业务逻辑,这些逻辑将根据用户的选择禁用或启用组合框中的复选框。 What I need to know, is how to disable those checkboxes. 我需要知道的是如何禁用这些复选框。 So for example: 因此,例如:

<Combobox CssClass="Assignees">
    <cb> <Item 1>
    <cb> <Item 2>
    <cb> <Item 3>
    <cb> <Item 4>

If item 4's checkbox is selected, then all other checkboxes are disabled. 如果选择了项目4的复选框,则所有其他复选框均被禁用。 If it's unselected, then everything is re-enabled. 如果未选中,则将重新启用所有功能。 If items 1,2 or 3 are selected, then Item 4's checkbox is disabled. 如果选择了项目1,2或3,则禁用项目4的复选框。

I've tried something like: 我已经尝试过类似的东西:

$(".AssigneeTag").find(":checkbox").click(
    function () {
        var allCheckboxes = $(this).closest(".AssigneeTag").find(":checkbox");
    });

Just to get all of the checkboxes in the combobox. 只是为了获得组合框中的所有复选框。 This is not returning anything. 这没有返回任何东西。 Then I know I need to go from here to inspect the itemdata to determine the "type" so that I can figure out what to hide or show. 然后,我知道我需要从这里检查itemdata以确定“类型”,以便找出隐藏或显示的内容。

Can anyone point me in the right direction? 谁能指出我正确的方向?

EDIT: As requested, the HTML. 编辑:根据要求,HTML。 I was able to dig this out of it. 我能够从中挖掘出来。 Just looking at it, I'm not able to wrap my head around what to do. 只是看着它,我无法将精力束之高阁。 The items loaded into the item list are actually objects that contain 3 fields; 加载到项目列表中的项目实际上是包含3个字段的对象。 a name, a guid, and a type. 名称,GUID和类型。 I'll need to look at the type to apply the business logic, but I'm not seeing it even appearing here: 我需要查看应用业务逻辑的类型,但是我什至没有看到它出现在这里:

<div id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo" class="RadComboBox RadComboBox_Default AssigneeTag" ItemDataBound="Assignees_Bound" style="width:160px;">
    <table summary="combobox" style="border-width:0;border-collapse:collapse;table-layout:fixed;width:100%">
        <tr class="rcbReadOnly">
            <td style="margin-top:-1px;margin-bottom:-1px;width:100%;" class="rcbInputCell rcbInputCellLeft">
                <input name="ctl00$MainContent$lsvTickets$ctrl0$lsvActions$cboAssignTo" type="text" class="rcbInput" id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_Input" value="" style="display: block;" readonly="readonly" />
            </td>
            <td style="margin-top:-1px;margin-bottom:-1px;" class="rcbArrowCell rcbArrowCellRight"><
                a id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a>
            </td>
        </tr>
    </table>

    <div class="rcbSlide" style="z-index:6000;">
        <div id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Default " style="float:left;display:none;">
            <div class="rcbScroll rcbWidth" style="width:100%;">
                <ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;">
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />Mike ITTest</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />Jeremy Stafford</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />John Bell Test (Info. Tech.)</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />Mike ITTest (Info. Tech.)</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />AG Cust Support</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />AG Eng Support</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />AG HR Support</li>
                    <li class="rcbItem "><input type="checkbox" class="rcbCheckBox" />AG IT Support</li>
                </ul>
            </div>
        </div>
    </div>
    <input id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_ClientState" name="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_ClientState" type="hidden" />
</div>

Well, to start with, there is a syntax error in your HTML that wouldnt work for me till I fixed it. 好吧,首先,您的HTML中有一个语法错误,在我修复它之前对我不起作用。

See Here: (error in return character after "<" before the tag "a") 请参见此处:(在标记“ a”之前,“ <”之后的返回字符错误)

<td style="margin-top:-1px;margin-bottom:-1px;" class="rcbArrowCell rcbArrowCellRight"><
    a id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a>
</td> //  also see no reason for display block on "a" as it will cause it to have 0 width and be invisible (more or less)

Changed Too 太改变了

<td style="margin-top:-1px;margin-bottom:-1px;" class="rcbArrowCell rcbArrowCellRight">
    <a id="ctl00_MainContent_lsvTickets_ctrl0_lsvActions_cboAssignTo_Arrow" style="overflow: hidden;position: relative;outline: none;">select</a>
</td>

Next, the check box issue, I wasn't sure which exact thing you wanted checked and unchecked, so I add a checkbox labeled "Check All" that you can click to check all, or if you uncheck an name, then check all is unchecked as well. 接下来,是复选框问题,我不确定您要选中和取消选中的是哪一项,因此我添加了一个标有“全部选中”的复选框,您可以单击该复选框以选中所有复选框,或者如果取消选中一个名称,则选中全部复选框也未经检查。 See the working jsFiddle HERE and see the jQuery code below: 请参阅可使用的jsFiddle此处,并查看下面的jQuery代码:

$(function() {
    $("#rcbCheckAll").on("change", function(e) {
        $(".rcbCheckBox").prop("checked", $(this).prop("checked"));
    });
    $(".rcbCheckBox").on("change", function(e) {
        if (!$(this).is("checked")) $("#rcbCheckAll").prop("checked", false);
    });
})​

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

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