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

时间:2012-06-01 16:27:41

标签: javascript jquery asp.net

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

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

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

我在我的控制下尝试了以下代码。

$(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" />

我必须使用$(this)。我对此很陌生。

帮助!

由于

千电子伏。

1 个答案:

答案 0 :(得分:0)

你的约会选择器有一个共同的类吗?您可以选择:

$('.className')

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

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

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

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

你可以通过这样的方式轻松检查逻辑:

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

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