Javascript 选择dropdownlist选项后显示隐藏文本框
我在选择dropdownlist时遇到了一个问题,在选择它时给出一个空值 代码如下:Javascript 选择dropdownlist选项后显示隐藏文本框,javascript,jquery,Javascript,Jquery,我在选择dropdownlist时遇到了一个问题,在选择它时给出一个空值 代码如下: <asp:GridView ID="gridview1" runat="server" AllowPaging="false" Width="99%" > <asp:BoundField DataField="NAME" HeaderText ="Name" HtmlEncode="false"/> <asp:BoundField DataField=
<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>
由于您将此作为对象的引用传递,因此可以这样做
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";
}
}
function Store\u Location\u onChange(对象){
if(objThis.value==“0”){
document.getElementById(“”.style.display=“”;
}
否则{
documentgetElementById(“”。value=“”;
document.getElementById(“”.style.display=“无”;
}
}
希望这有帮助 它有一个错误JavaScript运行时错误:当我尝试选择dropdownlistconsole此行
-->objThis.nextElementSibling
并查看返回的内容时,无法设置定义或空引用属性值!dropdownlist是由代码生成的,隐藏是一个sql查询IDN在选择dropdownlist时没有任何日志它继续显示此错误消息0x800a138f JavaScript运行时错误:在尝试选择dropdownlist时无法设置定义或空引用属性值我发现添加ClientIDMode=“Static”时出现问题由于文本框是生成无法读取的数字导致空值问题,如何在需要时显示文本框我尝试设置。style.display=“true”它将再次导致空值。。。
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";
}
}