javascript 如何隐藏单选按钮列表中的单选按钮之一?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22434765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide one of the radiobutton in radiobutton list?
提问by user3115280
Let say I want to hide one of the radio buttons with value 0, what code can make it visible = false? I was using Javascript, C# and ASP.NET.
假设我想隐藏值为 0 的单选按钮之一,什么代码可以使它可见 = false?我使用的是 Javascript、C# 和 ASP.NET。
<asp:ListItem Value="1"> 1 </asp:ListItem>
<asp:ListItem Value="2"> 2 </asp:ListItem>
<asp:ListItem Value="3"> 3 </asp:ListItem>
<asp:ListItem Value="4"> 4</asp:ListItem>
<asp:ListItem Value="0" Selected="True" Enabled="False">
foreach (ListViewDataItem item in ListView1.Items)
{
var rbl = (RadioButtonList)item.FindControl("rblSelect");
var selectedValue = int.Parse(rbl.SelectedItem.Value);
var selectedText = rbl.SelectedItem.Text;
var selectedIndex = rbl.SelectedIndex;
rbl.Items[0].Attributes.CssStyle.Add("visibility", "hidden");
}
回答by Sudhakar Tillapudi
Try This : From CodeBehind
试试这个:从 CodeBehind
MyRadioButtonList.Items[0].Attributes.CssStyle.Add("visibility", "hidden");
EDIT:
编辑:
int count = 0; //index of item tobe hidden
foreach (ListViewDataItem item in ListView1.Items)
{
var rbl = (RadioButtonList)item.FindControl("rblSelect");
var selectedValue = int.Parse(rbl.SelectedItem.Value);
var selectedText = rbl.SelectedItem.Text;
var selectedIndex = rbl.SelectedIndex;
if(count == 0)
rbl.Attributes.CssStyle.Add("visibility", "hidden");
count++;
}
回答by santosh singh
try this
试试这个
rbl.Items[0].Enabled = false;
回答by avinava basu
You need to amend the code as follows:
您需要修改代码如下:
rdBtn.items.remove("name_of_the_item");
In this case, the rdBtn
is the RadioButtonList ID
在这种情况下,rdBtn
是RadioButtonList ID
回答by Matsooh
In javascript it's possible to hide it with ".style.display"
在javascript中可以用“.style.display”隐藏它
var radio = document.getElementById('idOfYourRadiobutton');
radio.style.display = 'none'; // to hide
radio.style.display = 'block'; // to show