简体   繁体   English

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

[英]jQuery enable/disable asp.net controls based on user selection

I am generating following recurring markup from asp.net - 我正在从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">
        **...
        ...**

Once the user clicks on any row college radio button, containing child radio button has to be enabled. 用户单击任何行的大学单选按钮后,必须启用包含子级单选按钮。 Upon selecting other row, previously selected child radio buttons should be reset/disabled. 选择其他行后,应重设/禁用先前选择的子单选按钮。

I have achieved half success using jQuery, by obtaining selected row TR ID with following code, 通过使用以下代码获取选定的行TR ID,我使用jQuery取得了一半的成功,

    $(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
        });
    });

What other info am I missing ? 我还缺少什么其他信息?

Set the disabled attribute: 设置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');
    });
});

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

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