简体   繁体   中英

I want to create a custom function in jquery with few controls as parameters. How can I achieve this?

I have a checkbox (in ASP.NET) and want to enable/disable many ASP drop-down lists based on its checked attribute. Is it possible to do this using jQuery?

Here is my checkbox code:

<asp:CheckBox runat="server" ID="chb1" OnCheckedChanged="enablecheck(this,"#<%=ddl1.ClientID%>");" Checked="false"  />

Here is my jQuery code:

$(function enablecheck(chk,ddl) {
    $('[id$=chk]').on('click', function () {
        if ($(this).is(":checked")) {
           ddl.prop("disabled", false);
        } else {
            ddl.prop("disabled", true);
        }
    })
});

You could add a CSS class to the ddls you want to toggle in the code, using the CssClass property. These can be addressed in jQuery using

$('.myDdlCssClass').prop('disabled', true);

I'm not sure if ddls are rendered as pure select field or get some wrapping elements in asp. So actually

$('.myDdlCssClass select')

May be the correct selector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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