-1
我有2個下拉列表和一個文本框。我設法做了一個功能,在第一個下拉列表中選擇一個特定的值時,會出現第二個下拉列表。但是我無法讓第三個id(文本框)出現在對第二個下拉列表作出反應的地方。如何使第三個id屬性出現?
這裏是我到目前爲止
$(document).ready(function() {
change($("#<%=ddlMailJob.ClientID%>"));
$("#<%=ddlMBR.ClientID%>").change(function() {
change($(this));
});
});
function change(obj) {
if ($(obj).val() == "Y") {
$('#lblMBRY').show();
$('#ddlMBRY').show();
}
else {
$('#lblMBRY').hide();
$('#ddlMBRY').hide();
$('#lblMBRO').hide();
$('#txtMBRO').hide();
}
}
我想讓
$('#lblMBRO').hide(); $('#txtMBRO').hide();
出現第2次下拉列表中選擇,但我不知道我應該怎麼處理它。出現的值應該是「其他」
對不起。這是我的HTML
<td>
<asp:DropDownList ID="ddlMBR" 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="lblMBRY">Mailing Job</td>
<td id="ddlMBRY">
<asp:DropDownList ID="ddlMailJob" runat="server">
<asp:ListItem Selected="True" Value="empty">- - -</asp:ListItem>
<asp:ListItem Value="dlv">Deliver</asp:ListItem>
<asp:ListItem Value="pck">Pickup</asp:ListItem>
<asp:ListItem Value="Others">Others</asp:ListItem>
</asp:DropDownList>
</td>
<td class="colHead" id="lblMBRO">Others</td>
<td id="txtMBRO">
<asp:TextBox ID="txtOther" runat="server"></asp:TextBox>
</td>
確定第二你的HTML樣子? –
因爲已經有一個名爲change的函數,所以你可能想要避免調用它。你應該把它叫做changeVisible(obj) – Charles380
另一個小點:你將一個jquery對象傳遞給函數('change($(this));'),所以不需要把它包裝進去jquery again:'if($(obj).val()==「Y」){'can be'if(obj.val()==「Y」){'。 – Jamiec