【发布时间】:2014-05-10 09:34:55
【问题描述】:
我有一个包含 2 个值的下拉列表 - Y(是)和 N(否)。如果我选择值“Y”,则会显示某个<td>,但我无法实现该结果。我的代码有什么问题?到目前为止我只能隐藏它。
这是我的 asp.net 代码
<tr class="inputRows">
<td class="colHead">Mailing</td>
<td>
<asp:DropDownList ID="ddlMail" runat="server">
<asp:ListItem Selected="True" Value="empty">- - -</asp:ListItem>
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:DropDownList>
</td>
<td class="colHead" id="lblC">Carrier</td>
<td id="ddlC">
<asp:DropDownList ID="ddlCarrier" runat="server">
<asp:ListItem Selected="True" Value="empty">- - -</asp:ListItem>
<asp:ListItem Value="Dlv">Delivery</asp:ListItem>
<asp:ListItem Value="Pck">Pick-up</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
这是我的 jQuery 代码
$(document).ready(function () {
$('#lblC').hide();
$('#ddlC').hide();
var i = document.getElementById("ddlMail");
var value = i.options[i.selectedIndex].text;
if (value == "Y") {
$('#lblC').show();
$('#ddlC').show();
}
});
【问题讨论】:
-
使用组合的客户端 ID 或使用 $("select[id$=DDL]").val();
-
你好,什么是 asp:ListItem ?
标签: jquery asp.net select selecteditem