我正在后面的代码中使用.VB进行ASPX项目。目标是在页面加载时隐藏两个div。然后,当用户单击“否”单选按钮时,它将在其下显示隐藏的div。单选按钮是asp列表项。
下面的代码有效,但在页面加载时div可见。我假设它不是我的VB代码或JS代码不会在页面加载时隐藏。
这是后面的VB代码。
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
For Each li As ListItem In rbPickUpOnTime.Items
If li.Value = "Y" Then
li.Attributes.Add("onclick", "javascript:hidePickup();")
End If
If li.Value = "N" Then
li.Attributes.Add("onclick", "javascript:showPickup();")
End If
Next
For Each li As ListItem In rbDeliveryOnTime.Items
If li.Value = "Y" Then
li.Attributes.Add("onclick", "javascript:hideDelivery();")
End If
If li.Value = "N" Then
li.Attributes.Add("onclick", "javascript:showDelivery();")
End If
Next
这是JavaScript:
function hidePickup() {
document.getElementById('pnlPickupNo').style.display = 'none';
};
function showPickup() {
document.getElementById('pnlPickupNo').style.display = 'block';
};
function hideDelivery() {
document.getElementById('pnlDeliveryNo').style.display = 'none';
};
function showDelivery() {
document.getElementById('pnlDeliveryNo').style.display = 'block';
};
最后,这是它需要显示/隐藏的ASPX面板之一:
<div class="container" style="margin-top: 20px;">
<div class="centerContainer" style="width: 230px;">
<label class="Emphasis">I can pickup on time </label>
<asp:RadioButtonList ID="rbPickUpOnTime" runat="server"
RepeatDirection="Horizontal"
Style="margin-left: 60px;" TabIndex="2" AutoPostBack="false">
<asp:ListItem Text="Yes" Value="Y" Selected="True" />
<asp:ListItem Text="No" Value="N" />
</asp:RadioButtonList>
</div>
<asp:Panel ID="pnlPickupNo" runat="server" >
<div class="centerContainer ui-widget-content" style="width: 230px;">
<label>If No, ETA to pickup </label>
<table style="margin-left: 15px;">
.....
</table>
</div>
有什么建议么?
最佳答案
如果使用的是.Net 4.0或更高版本,则可以使用“客户端ID模式静态”在服务器端生成相同的ID。
如果您没有提及任何内容,则可以使用ClientID代替直接使用ID
例如,如果您的ID为'pnlPickupNo'
,则可以使用以下语法来获得客户机ID:
<%# 'pnlPickupNo'.ClientID %>
希望这可以帮助..
关于javascript - JavaScript使用ASP RadioButtonList显示/隐藏div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23366663/