我有一个DropDownList作为自定义控件插入到主窗口弹出窗口中的子窗体中。我为DropDownList和我试图启用/禁用的文本框编码了唯一的CssClass标识符。我只想为DropDownList值317和318启用文本框,其他所有文本框都应该禁用文本框。这是问题...如果我打开弹出窗口并选择317/318以外的操作,它会按预期禁用文本框。然后,如果我改变主意并选择317或318,则不启用文本框。这似乎很奇怪,它部分有效。
我的主页面中有以下jquery代码:
<script language="javascript" type="text/javascript">
var _CASE_RESERVE_ACTION = "317";
var _LEGAL_RESERVE_ACTION = "318";
function pageLoad() {
$(".statusActionDDLCssClass").change(function() {
var value = $(this).val();
if (value == _CASE_RESERVE_ACTION || value == _LEGAL_RESERVE_ACTION)
$(".statusActionAmountCssClass").attr('enabled', 'enabled');
else
$(".statusActionAmountCssClass").attr('disabled', 'disabled');
});
}
</script>
以下是DropDownList的自定义控件:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="StStatusActionLookup.ascx.cs" Inherits="Company.Solutions.Web.Controls.StStatusActionLookup" %>
<div id="mainControlContainer" style="width:99%; padding:8px;">
<div id="comboContainer" style="float:left; padding-top:12px;padding-left:5px; padding-right:5px; padding-bottom:3px;">
<asp:UpdatePanel ID="update1" runat="server" UpdateMode="Always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chkComments" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="chkDenials" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="chkOther" EventName="CheckedChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddlLookup" width="240px" CssClass="statusActionDDLCssClass" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="filterContainer" style="text-align:left;padding-left:6px;width:275px">
<fieldset style="width:260;">
<legend>Filters</legend>
<asp:CheckBox ID="chkComments" runat="server" Text="Comments" AutoPostBack="true" />
<asp:CheckBox ID="chkDenials" runat="server" Text="Denials" AutoPostBack="true" />
<asp:CheckBox ID="chkOther" runat="server" Text="Other" AutoPostBack="true" />
</fieldset>
</div>
</div>
这是我的子表单文本框(txtStatusActionAmount):
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="StatusActionAddSubform.ascx.cs"
Inherits="Company.Solutions.Web.Controls.StatusActionAddSubform" %>
<%@ Register TagPrefix="st" TagName="StatusActionLookup" Src="~/Controls/StStatusActionLookup.ascx" %>
<div class="NinetyNinePercentWide">
<div class="NinetyNinePercentWide EightPixelBottomMargin">
<div class="RowHeader" style="padding-top: 20px;">
<span>Action:</span>
</div>
<div>
<xy:StatusActionLookup ID="statusActionLookup1" runat="server" />
</div>
</div>
<div class="NinetyNinePercentWide EightPixelBottomMargin">
<div class="quarterWidthDiv">
<span>New Status:</span>
<asp:Literal runat="server" Text=" " ID="spc2" />
<asp:DropDownList runat="server" ID="ddlNewStatus">
<asp:ListItem Selected="True" Value="" Text="" />
<asp:ListItem Value="01" Text="Open" />
<asp:ListItem Value="02" Text="Closed" />
</asp:DropDownList>
</div>
<div class="quarterWidthDiv">
<span>Date:</span>
<asp:Literal runat="server" Text="  " ID="spc1" />
<asp:TextBox ID="txtStatusActionDate" runat="server" Columns="10" MaxLength="10"
Style="width: 35%;" CssClass="statusActionDate" />
<cc1:CalendarExtender ID="txtStatusActionDate_CalendarExtender" runat="server" Enabled="True"
TargetControlID="txtStatusActionDate" />
<cc1:MaskedEditExtender runat="server" ID="txtStatusActionDate_MaskedEditExtender"
Enabled="True" Mask="99/99/9999" MaskType="Date" TargetControlID="txtStatusActionDate"
UserDateFormat="MonthDayYear" />
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtStatusActionDate"
Type="Date" Operator="DataTypeCheck" ErrorMessage="Invalid Date" > </asp:CompareValidator>
</div>
<div class="quarterWidthDiv">
<asp:Label runat="server" ID="lblStatusActionAmount" AssociatedControlID="txtStatusActionAmount"
Text="Amount:" />
<asp:TextBox ID="txtStatusActionAmount" runat="server" Style="width: 30%;" CssClass="statusActionAmountCssClass" />
</div>
<div class="quarterWidthDiv">
<asp:Label runat="server" ID="lblClaimant" AssociatedControlID="ddlClaimant" Text="Claimant:" />
<asp:DropDownList ID="ddlClaimant" runat="server" onchange="mailOrStatusActionTextChanged()">
<asp:ListItem Selected="True" Value="" Text="" />
<asp:ListItem Value="1" Text="Primary" />
<asp:ListItem Value="2" Text="Secondary" />
</asp:DropDownList>
</div>
</div>
<div class="NinetyNinePercentWide EightPixelBottomMargin" style="margin-top: 2px;">
<div class="RowHeader">
<asp:Label runat="server" ID="lblStatusActionReason" AssociatedControlID="txtStatusActionReason"
Text="Reason:" />
</div>
<div style="padding-left: 12px;">
<asp:TextBox ID="txtStatusActionReason" runat="server" TextMode="MultiLine" Rows="2"
MaxLength="25" CssClass="StatusReasonWidth" onchange="mailOrStatusActionTextChanged()" />
<asp:CustomValidator ID="cstmValStatusActionReason" runat="server" ControlToValidate="txtStatusActionReason"
ErrorMessage="String is too long" />
</div>
</div>
</div>
谢谢你, Jim在Suwanee,GA
答案 0 :(得分:4)
我不相信表单元素的'enabled'属性,请尝试
$(".statusActionAmountCssClass").attr('disabled', false);
修改强>
请注意,attr()
的含义和用法在jQuery 1.6中已更改。虽然上述内容可能仍然有用,但请务必测试并了解attr()
和prop()
http://blog.jquery.com/2011/05/03/jquery-16-released/
在1.6版本中,我们拆分了DOM属性的处理 和DOM属性分成单独的方法。新的.prop()方法设置 或获取DOM元素的属性,并删除.removeProp() 属性。在过去,jQuery之间没有明确界限 属性和属性。通常,DOM属性代表 从文档中检索的DOM信息的状态,例如 标记中的value属性。 DOM 属性表示文档的动态状态;例如,如果 用户点击上面的输入元素并键入def .prop(“value”)是abcdef,但.attr(“value”)仍然是abc。
答案 1 :(得分:2)
$(".statusActionAmountCssClass").attr('disabled', true)
无效
使用:$(".statusActionAmountCssClass").attr('disabled', 'disabled')
和$(".statusActionAmountCssClass").removeAttr('disabled', 'disabled')
这将起作用
答案 2 :(得分:0)
我就是这样做的。
$("input[name='votingmode']").change(function () {
if ($("input[name='votingmode']:checked").val() == '1') {
$("#plusplus").attr("disabled", "disabled");
$("#minusminus").attr("disabled", "disabled");
} else if ($("input[name='votingmode']:checked").val() == '3') {
$("#plusplus").removeAttr("disabled", "disabled");
$("#minusminus").removeAttr("disabled", "disabled");
});