我有一个带有以下 aspx 标记的小页面
<fieldset style="width:40%; margin-left:50px;">
<legend> Site User Role Management</legend>
<asp:Label ID="lblSiteUserDDl" runat="server" AssociatedControlID="ddlSiteUsers"
Text="Manage the roles in which a user is registered by selecting the user from the dropdown list below."></asp:Label>
<asp:DropDownList ID="ddlSiteUsers" runat="server" CssClass="dropdowns" AutoPostBack="True" ClientIDMode="Static" />
<br /><br />
<asp:UpdatePanel ID="updplRoleChange" runat="server" ClientIDMode="Static">
<ContentTemplate>
<fieldset id="rolemanagement" style="width:80%;" Visible="false" runat="server" >
<legend id="rolemgmtlegend" runat="server"></legend>
<asp:Label ID="lblCurrentRole" runat="server" CssClass="literaltext"></asp:Label><br />
<asp:Label ID="lblSiteUserRole" runat="server" CssClass="literaltext"></asp:Label><br /><br />
<asp:RadioButtonList id="rblstRoleChange" runat="server">
<asp:ListItem selected="true">Add Role to User</asp:ListItem>
<asp:ListItem>Remove Role from User</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="ddlUserRoles" CssClass="dropdowns" runat="server" AutoPostBack="True" ClientIDMode="Static" /><br />
<asp:Button ID="submitrolechange" Text="Submit Role Change" CssClass="buttons" runat="server" ClientIDMode="Static" Visible="False" />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSiteUsers" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="submitrolechange" EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
</fieldset>
和下面的 JQuery
<script>
$(document).ready(function () {
$('#ddlSiteUsers').change(function() {
$(this).css({ 'color': 'black', 'font-size': '1.1em', 'font-weight': 'bold' });
});
//
$('#updplRoleChange select').change(function () {
$('#submitrolechange').show();
$(this).css({ 'color': 'black', 'font-size': '1.1em', 'font-weight': 'bold' });
});
});
</script>
第一个功能有效,第二个无效。使用第一个下拉选择器后,更新面板中没有为标记生成 html,因此我什至不确定选择器 id 是否实际上保持静态。