我在选择下拉列表时遇到问题,它在选择时给出了空值
以下是代码:
DROP TABLE TempTable
的javascript:
<asp:GridView ID="gridview1" runat="server" AllowPaging="false" Width="99%" >
<asp:BoundField DataField="NAME" HeaderText ="Name" HtmlEncode="false"/>
<asp:BoundField DataField="ID " HeaderText ="ID " HtmlEncode="false"/>
<asp:TemplateField HeaderText ="Location">
<ItemTemplate>
<asp:DropDownList ID="ddlfruitAgent" runat="server" onchange="Store_Location_onChange(this)" />
<asp:TextBox ID="StoreLocation" runat="server" TextMode="MultiLine" Rows="2" style="width:97%;display:none" />
</ItemTemplate>
</asp:TemplateField>
答案 0 :(得分:0)
由于您将this
作为对象的引用传递,因此您可以这样做
function Store_Location_onChange(objThis) {
if (objThis.value == "0") {
objThis.nextElementSibling.style.display = "";
}
else {
objThis.nextElementSibling.value = "";
objThis.nextElementSibling.style.display = "none";
}
}
或其他方式是
function Store_Location_onChange(objThis) {
if (objThis.value == "0") {
document.getElementById("<%= StoreLocation.ClientID %>").style.display = "";
}
else {
documentgetElementById("<%= StoreLocation.ClientID %>").value = "";
document.getElementById("<%= StoreLocation.ClientID %>").style.display = "none";
}
}
希望这有帮助!