尝试锁定自定义控件,但在页面中有多个控件时出现问题

Trying to lock a custom control, but having problems when more than one of the control in the page

本文关键字:控件 问题 自定义控件 锁定      更新时间:2023-09-26

我有一个自定义控件,我将其加载到页面上三次。

自定义控件由文本框和自定义日期选取器控件组成。

我正在尝试锁定所有人的日期选择器控件。

我在控件中尝试了以下代码。

$(document).ready(function() {
    debugger;
    var mySelector = '#' + $('[id$=''_SignatureNonPoliceControl'']', $(this)).attr('id');
    $(mySelector.replace('_SignatureNonPoliceControl', '_SignatureDatePicker_DatePickerControl')).BaseControlPlugin(BaseControlMethodsEnum.SetLocked, true);
});

但是,这只会锁定第一个并执行三次。

我的控件是这样设置的

            <uc8:SignatureCaptureNonPolice ID="DetaineeSignature" runat="server" Caption = "Person's Signature to Comments " RetainValueWhenDisabled="true" />
            <uc1:GenericDropDownList Caption="Reason For Not Signing " ID="DetaineeReasonNotSignedGenericDropDownList" runat="server" />
            <uc8:SignatureCaptureNonPolice ID="AppropriateAdultSignature" runat="server" Caption = "Appropriate Adults<br />Signature to Comments " RetainValueWhenDisabled="true" />
            <uc8:SignatureCaptureNonPolice ID="InterpreterSignature" runat="server" Caption = "Interpreter's Signature<br />to Comments " RetainValueWhenDisabled="true" />

我必须使用 $(这个)吗? 我对此很陌生。

帮助!

谢谢

凯文。

您的日期选择器有公共类吗?你可以选择它:

$('.className')

另一种选择是在一个选择器中用逗号分隔您的所有 ID:

$('#firstID,#secondID,#thirdID')

然后我假设您想对它们应用锁定的类?

$('.className').addClass("locked");

你可以通过做这样的事情来轻松检查这个逻辑:

if (this.hasClass("locked") {
    // this is locked.
}

在此处阅读有关选择器的更多信息:http://api.jquery.com/category/selectors/