我想要一组单选按钮看起来像一组切换按钮(但仍然像单选按钮一样工作).它们看起来不像切换按钮.
我怎么能用CSS和HTML做到这一点?
编辑:当选中/取消选中按钮时,我会满意地让小圆圈消失并改变样式.
如何使用javascript调用radiobutton列表上的onclick?
当我设置一个RadioButtonList时,它会为它创建一个表格布局,我不想要这个...我该如何摆脱它?
它可能是重复但我搜索过,并没有设法在这里找到这样的问题.
我的页面上有一些放射学家.我面临的问题是单选按钮的文本没有显示在内部的辐射按钮上.我已将repeatLayout放到Table和Flow中,但两者都没有工作.我试图添加一种显示风格:内联; 但这也不起作用(虽然它在复选框上做了,我想也许它也可以在这里工作).
这只是一个普通的放射学家:
<asp:RadioButtonList ID="radRace" CssClass="radioButtonList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Race 1</asp:ListItem>
<asp:ListItem>Race 2</asp:ListItem>
<asp:ListItem>Race 3</asp:ListItem>
<asp:ListItem>Race 4</asp:ListItem>
</asp:RadioButtonList>
ul.radioButtonList { list-style:none; margin: 0; padding: 0;}
ul.radioButtonList.horizontal li { display: inline;}
Run Code Online (Sandbox Code Playgroud)
当repeatLayout在桌子上时:

当repeatLayout在Flow上时:

有人可以帮助我如何设置它,以便文本显示在单选按钮旁边...如果它有所作为,radioButtonList在一个表....
解:
这就是单选按钮列表现在的样子:
<asp:RadioButtonList ID="radRace" CssClass="radioButtonList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Race 1</asp:ListItem>
<asp:ListItem>Race 2</asp:ListItem>
<asp:ListItem>Race 3</asp:ListItem>
<asp:ListItem>Race 4</asp:ListItem>
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)
这是cssClass:
<style type="text/css">
.radioButtonList { list-style:none; margin: 0; padding: 0;}
.radioButtonList.horizontal li { display: inline;}
.radioButtonList label{
display:inline;
}
</style>
Run Code Online (Sandbox Code Playgroud) 我有一个ASP.NET RadioButtonList,它使用RepeatDirection ="Horizontal"显示四个项目,以便在一行上显示它们.我正在使用RepeatLayout ="Flow"来避免表的标记.但是,这会导致列表中的项目彼此相邻放置,这看起来不太好.
因此,我尝试使用表格布局来利用CellSpacing和/或CellPadding属性.不幸的是,这些属性会影响表格中的垂直和水平间距/填充,所以当我得到水平间距时,我也会得到不希望的垂直间距.
在这一点上,我是这样的:
<asp:RadioButtonList ID="rblMyRadioButtonList" runat="server"
RepeatDirection="Horizontal"
RepeatLayout="Flow" >
<asp:ListItem Selected="false" Text="Item One " Value="Item_1" />
<asp:ListItem Selected="false" Text="Item Two " Value="Item_2" />
<asp:ListItem Selected="false" Text="Item Three " Value="Item_3" />
<asp:ListItem Selected="false" Text="Item Four " Value="Item_4" />
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)
......对我尖叫"你做得不对劲!"
完成此任务的正确方法是什么?
有没有办法在单选按钮列表中的输入项上设置CSS类?我想在jQuery中按类引用这些表单值.
给定一个ASP.NET RadioButtonList,在ListItems上设置类:
<asp:RadioButtonList ID="RadioButtonList" runat="server">
<asp:ListItem class="myClass" Text="Yes" Value="1" />
<asp:ListItem class="myClass" Text="No" Value="0" />
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)
将呈现为:
<span id="RadioButtonList" class="radioButtonListField myClass">
<span class="myClass">
<input id="RadioButtonList_0" type="radio" value="1"
name="RadioButtonList"/>
<label for="RadioButtonList_0">Yes</label>
</span>
<span class="myClass">
<input id="RadioButtonList_1" type="radio" value="0"
name="RadioButtonList"/>
<label for="RadioButtonList_1">No</label>
</span>
</span>
Run Code Online (Sandbox Code Playgroud)
不幸的是,"myClass"类被添加到<span>包含单选按钮项而不是它<input>自身.我怎么能让它看起来像这样:
<span id="RadioButtonList" class="radioButtonListField myClass">
<span>
<input id="RadioButtonList_0" class="myClass" type="radio" value="1"
name="RadioButtonList"/>
<label for="RadioButtonList_0">Yes</label>
</span>
<span>
<input id="RadioButtonList_1" class="myClass" type="radio" value="0"
name="RadioButtonList"/>
<label for="RadioButtonList_1">No</label>
</span>
</span>
Run Code Online (Sandbox Code Playgroud)
(这甚至没有涉及将类添加到动态绑定RadioButtonLists的问题.)
我想获得一些选项(比如付款方式现金,信用卡等)并将这些选项绑定到单选按钮.我相信MVC 3中没有RadioButtonList.
此外,一旦绑定了无线电,我想在编辑答案时向用户显示先前选择的选项.
嘿,我有一个radiobuttonlist,并尝试根据会话变量设置其中一个radiobuttons,但证明是不可能的.
<asp:radiobuttonlist id="radio1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:listitem id="option1" runat="server" value="All"/>
<asp:listitem id="option2" runat="server" value="1" />
<asp:listitem id="option3" runat="server" value="2" />
</asp:radiobuttonlist>
Run Code Online (Sandbox Code Playgroud)
即如何在后面的代码中将option2设置为选中?
我在用:
if (RadioButtonList_VolunteerType.SelectedItem != null)
Run Code Online (Sandbox Code Playgroud)
或怎么样:
if (RadioButtonList_VolunteerType.Index >= 0)
Run Code Online (Sandbox Code Playgroud)
或者怎么样(根据Andrew Hare的回答):
if (RadioButtonList_VolunteerType.Index > -1)
Run Code Online (Sandbox Code Playgroud)
对于那些可能阅读此问题的人,以下不是有效的方法.正如Keltex指出的那样,所选值可能是一个空字符串.
if (string.IsNullOrEmpty(RadioButtonList_VolunteerType.SelectedValue))
Run Code Online (Sandbox Code Playgroud) 我有以下HTML源代码
<form name="Register1" action="Register.aspx" id="registerform" method="post"
runat="server" style="margin-top: 15px;">
<input type="radio" name="Gender" value="male" />male
<input type="radio" name="Gender" value="female" />female
</form>
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在c#页面中将所选值变为变量?
我试过这个:
Gender = Request.Form["Gender"].ToString();
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
radiobuttonlist ×10
asp.net ×7
css ×3
c# ×2
html ×2
radio-button ×2
formatting ×1
javascript ×1
listitem ×1
markup ×1
onclick ×1
razor ×1
togglebutton ×1
validation ×1