代码应该在页面加载时隐藏文本框,并仅在用户选择“其他”时显示它。
<script type="text/javascript">
$(document).ready(function () {
$('#ddlMajor').change(function () {
if ($(this).val() == 'Other') {
// $('#txtOther').show();
$('#txtOther').css('display', 'inline');
}
else {
// $('#txtOther').hide();
$('#txtOther').css('display', 'block');
}
});
});
</script>
<asp:TextBox runat="server" ID="txtOther" style="display:none;" > </asp:TextBox>
<asp:DropDownList runat="server" ID="ddlMajor">
<asp:ListItem Value="Accounting">Accounting</asp:ListItem>
<asp:ListItem Value="Management">Management</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
clientId
属性来插入正确的ID。 - Jacob Mattison