【问题标题】:how to disable/enable multiple checkboxes inside of a radcombobox using jquery?如何使用 jquery 禁用/启用 radcombobox 内的多个复选框?
【发布时间】:2012-04-08 10:15:15
【问题描述】:

我有一个 ItemTemplate,其中每个项目都包含一个启用了复选框的 RadComboBox。我需要应用一些业务逻辑,根据用户的选择禁用或启用组合框中的复选框。我需要知道的是如何禁用这些复选框。比如:

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

如果第 4 项的复选框被选中,则所有其他复选框都将被禁用。如果未选中,则将重新启用所有内容。如果项目 1,2 或 3 被选中,则项目 4 的复选框被禁用。

我尝试过类似的方法:

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

只是为了获取组合框中的所有复选框。这不是返回任何东西。然后我知道我需要从这里检查 itemdata 以确定“类型”,以便找出要隐藏或显示的内容。

谁能指出我正确的方向?

编辑: 根据要求,HTML。我能够从中挖掘出来。只是看着它,我不知道该怎么做。加载到项目列表中的项目实际上是包含 3 个字段的对象;名称、向导和类型。我需要查看类型以应用业务逻辑,但我什至没有看到它出现在这里:

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

【问题讨论】:

  • 由于您被困在 Telerik 控件的混乱抽象中,请退后一步,查看客户端上的 HTML 输出。也向我们展示 HTML,因为您的 jQuery 需要使用它。

标签: javascript jquery asp.net telerik


【解决方案1】:

首先,您的 HTML 中有一个语法错误,在我修复它之前对我不起作用。

参见此处:(标记“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)

也变了

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

接下来,复选框问题,我不确定您要选中和取消选中哪个确切的东西,所以我添加了一个标有“选中所有”的复选框,您可以单击以选中所有,或者如果您取消选中一个名称,那么检查所有也未选中。 See the working jsFiddle HERE 并查看下面的 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);
    });
})​

【讨论】:

    猜你喜欢
    • 2012-11-02
    • 1970-01-01
    • 2016-11-19
    • 2017-01-15
    • 2021-03-07
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多