gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'style' of null in javascript function:

转载 作者:行者123 更新时间:2023-11-28 03:12:25 28 4
gpt4 key购买 nike

从 .aspx 文件调用 JavaScript 函数时,出现下拉列表的错误,如“validation.js:22 Uncaught TypeError: Cannot read property 'style' of null”。

BlueINK.aspx

<asp:DropDownList ID="diGuj" onchange="javascript:optionChange(this);" runat="server">
<asp:ListItem style="display:none">--Select--</asp:ListItem>
<asp:ListItem Value="1">yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:DropDownList>

<td align="right" style="width: 172px">
<strong id="durationHome" style="display:none"><span class="redtext">* </span> Duration :</strong>
</td>
<td class="auto-style1" align="left">
<asp:DropDownList ID="joinMo1" runat="server" style="display:none">
<asp:ListItem Selected Value="january">Jan</asp:ListItem>
<asp:ListItem>Feb</asp:ListItem>
<asp:ListItem>Mar</asp:ListItem>
<asp:ListItem>Apr</asp:ListItem>
<asp:ListItem>May</asp:ListItem>
<asp:ListItem>Jun</asp:ListItem>
<asp:ListItem>Jul</asp:ListItem>
<asp:ListItem>Aug</asp:ListItem>
<asp:ListItem>Sep</asp:ListItem>
<asp:ListItem>Oct</asp:ListItem>
<asp:ListItem>Nov</asp:ListItem>
<asp:ListItem>Dec</asp:ListItem>
</asp:DropDownList>
</td>

Validation.js

function optionChange(textObj) {
a = textObj.value;
if (a == 1) {
document.getElementById("durationHome").style.display = "block";
document.getElementById("joinMo1").style.display = "block";
}
else {
document.getElementById("durationHome").style.display = "none";
document.getElementById("joinMo1").style.display = "none";
}
}

最佳答案

尝试,

document.getElementById("<%= joinMo1.ClientID %>").style.display = "none/block";

代替,

document.getElementById("joinMo1").style.display="none/block"

关于javascript - 未捕获的类型错误 : Cannot read property 'style' of null in javascript function:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59980536/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com