代码之家  ›  专栏  ›  技术社区  ›  Abhijeet

jQuery根据用户选择启用/禁用asp.net控件

  •  1
  • Abhijeet  · 技术社区  · 13 年前

    我正在从asp.net生成以下重复标记-

            <tr id="trRow0" class="trClass">
                <td id="cell0" class="tdClass">
                    <input id="MainContent_rptColleges_rbCollege_0" type="radio" name="ctl00$MainContent$rptColleges$ctl01$rbCollege" value="mit" />
                    mit
                </td>
                <td>
                    <ul>
                        <li>
                            <input id="MainContent_rptColleges_rptCourses_0_rbCourse_0" type="radio" name="ctl00$MainContent$rptColleges$ctl01$rptCourses$ctl01$rbCourse" value="computer science" />
                            &nbsp; computer science
                        </li>
                        <li>
                            <input id="MainContent_rptColleges_rptCourses_0_rbCourse_1" type="radio" name="ctl00$MainContent$rptColleges$ctl01$rptCourses$ctl02$rbCourse" value="mechanical engg." />
                            &nbsp; mechanical engg.
                        </li>
                    </ul>
                </td>
            </tr>
            <tr id="trRow1" class="trClass">
                <td id="cell1" class="tdClass">
            **...
            ...**
    

    一旦用户单击任意一行的学院单选按钮,就必须启用包含子单选按钮。选择其他行后,应重置/禁用先前选择的子单选按钮。

    我使用jQuery获得了一半的成功,通过以下代码获得选定的行TR ID,

        $(document).ready(function myfunction() {            
            $('[id*=rbCollege]').click(function (e) {
                var selectedCollegeRow = jQuery(this).parent().parent().attr("id");
                $(selectedCollegeRow).find('input[name$=rbCourse]'). //code to enable disable radio
            });
        });
    

    我还缺少什么其他信息?

    1 回复  |  直到 13 年前
        1
  •  0
  •   Royce Feng    13 年前

    设置 disabled 属性:

    $(document).ready(function myfunction() {            
        $('[id*=rbCollege]').click(function (e) {
            var selectedCollegeRow = jQuery(this).parent().parent().attr("id");
            $(selectedCollegeRow).find('input[name$=rbCourse]').attr('disabled', 'true');
        });
    });