Javascript document.getelementbyId始终返回null
设置面板可见性时遇到问题 但在更改时,JavaScript返回空引用异常 JavaScript运行时错误:无法获取未定义或空引用的属性“setAttribute” 我想根据单选按钮(Javascript document.getelementbyId始终返回null,javascript,jquery,Javascript,Jquery,设置面板可见性时遇到问题 但在更改时,JavaScript返回空引用异常 JavaScript运行时错误:无法获取未定义或空引用的属性“setAttribute” 我想根据单选按钮(RbMarketing)更改使面板TrMarketingDetails可见 JavaScript function trVisible(val) { var selected = $("#" + val.id + " input:radio:checked").val(); if (selected
RbMarketing
)更改使面板TrMarketingDetails
可见
JavaScript
function trVisible(val) {
var selected = $("#" + val.id + " input:radio:checked").val();
if (selected == "1") {
document.getElementById('<%=TrMarketingDetails.ClientID %>').setAttribute("style", "visibility: visible");
document.getElementById('<%= hfdMarket.ClientID %>').value = 'Y';
}
else if (selected == "2") {
document.getElementById('<%=TrMarketingDetails.ClientID %>').setAttribute("style", "visibility: hidden");
}
}
函数trVisible(val){
所选变量=$(“#”+val.id+“输入:收音机:已选中”).val();
如果(所选==“1”){
document.getElementById(“”).setAttribute(“样式”,“可见性:可见”);
document.getElementById(“”).value='Y';
}
否则如果(所选==“2”){
document.getElementById(“”).setAttribute(“样式”,“可见性:隐藏”);
}
}
AXPX代码
<tr>
<td style="font-weight: bold" align="left" class="style4">
Marketing facilities available
</td>
<td style="font-weight: bold" class="style23">
<asp:RadioButtonList ID="RbMarketing" runat="server" DataTextField="Yes" onchange="trVisible(this);"
RepeatDirection="Horizontal">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="2"></asp:ListItem>
</asp:RadioButtonList>
<asp:HiddenField ID="hfdMarket" runat="server" />
<%--OnSelectedIndexChanged="RbMarketing_SelectedIndexChanged" AutoPostBack="True"--%>
</td>
</tr>
<asp:Panel ID="TrMarketingDetails" runat="server" Style="visibility: hidden" EnableViewState="true">
<tr>
<%--visible="false"--%>
<td runat="server" style="border: none;" class="style7" align="left">
Details :
</td>
<td runat="server" style="border: none;" class="style26" align="left">
<asp:TextBox ID="TextMarketingDetails" runat="server" CssClass="textboxCss" autocomplete="off"
MaxLength="100" Enabled="True" ondrop="return false;" Width="300px" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="Requiredfieldvalidator49" runat="server" Display="None"
ControlToValidate="TextMarketingDetails" ValidationGroup="grp1" ForeColor="#F00000"
SetFocusOnError="true" ErrorMessage="Please enter Marketing details" Enabled="false"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" PopupPosition="Right"
TargetControlID="Requiredfieldvalidator49">
</asp:ValidatorCalloutExtender>
</td>
</tr>
</asp:Panel>
市场推广设施
细节:
你就这样改变
function trVisible(val) {
var selected = $("#" + val.id + " input:radio:checked").val();
if (selected == "1") {
document.getElementById('<%=TrMarketingDetails.ClientID %>').style.visibility = "visible";
document.getElementById('<%= hfdMarket.ClientID %>').value = 'Y';
}
else if (selected == "2") {
document.getElementById('<%=TrMarketingDetails.ClientID %>').style.visibility = "hidden";
}
}
函数trVisible(val){
所选变量=$(“#”+val.id+“输入:收音机:已选中”).val();
如果(所选==“1”){
document.getElementById(“”).style.visibility=“可见”;
document.getElementById(“”).value='Y';
}
否则如果(所选==“2”){
document.getElementById(“”).style.visibility=“hidden”;
}
}
您已经在代码中使用了jquery语法,那么可以通过jquery语法这样做
$('#<%=TrMarketingDetails.ClientID %>').show();
$('#<%=TrMarketingDetails.ClientID %>').hide();
$('#').show();
$('#')。隐藏();
能否共享呈现的html请提供html输出。能否只提供客户端html代码?我不确定标记id是否匹配亲爱的Hanks..哦,对不起,我从来没有使用过这些东西…我在更改javascript代码时更改了它我收到javascript运行时错误:无法获取未定义或空引用的属性“style”。在使用jQuery代码时没有更改occour
$('#<%=TrMarketingDetails.ClientID %>').show();
$('#<%=TrMarketingDetails.ClientID %>').hide();