以下代码在IE中很有用,但在FF或Safari中却不行.我不能为我的生活找出原因.如果您选择"禁用2个单选按钮"选项,则代码应禁用单选按钮.如果选择"启用两个单选按钮"选项,则应启用单选按钮.这两个都有效......
但是,如果您不使用鼠标在2个选项之间移动("启用..."和"禁用..."),则单选按钮似乎未被正确禁用或启用,直到您单击其他任何位置在页面上(不是单选按钮本身).
如果有人有时间/好奇/感觉有帮助,请将下面的代码粘贴到html页面并在浏览器中加载.它在IE中运行良好,但问题表现在FF(我的情况下为3)和Safari,都在Windows XP上.
<html>
<head>
<script language="javascript">
function SetLocationOptions() {
var frmTemp = document.frm;
var selTemp = frmTemp.user;
if(selTemp.selectedIndex >= 0) {
var myOpt = selTemp.options[selTemp.selectedIndex];
if(myOpt.attributes[0].nodeValue == '1') {
frmTemp.transfer_to[0].disabled = true;
frmTemp.transfer_to[1].disabled = true;
frmTemp.transfer_to[2].checked = true;
} else {
frmTemp.transfer_to[0].disabled = false;
frmTemp.transfer_to[1].disabled = false;
}
}
}
</script>
</head>
<body>
<form name="frm" action="coopfunds_transfer_request.asp" method="post">
<select name="user" onchange="javascript: SetLocationOptions()">
<option value="" />Choose One
<option value="58" user_is_tsm="0" />Enable both radio buttons
<option value="157" user_is_tsm="1" />Disable …Run Code Online (Sandbox Code Playgroud) 就像标题所说,JavaScript中获取具有给定名称的页面上所有单选按钮的最佳方式是什么?最终,我将使用它来确定选择了哪个特定的单选按钮,这是另一种表达问题的方法:
给定JavaScript中的字符串变量,如何判断该字符串的确切单选按钮输入元素(如果有),因为它的名称当前已被选中?
我没有使用jQuery.如果您想提供jQuery答案,请继续.其他人可能会发现它很有用.但它不会帮助我,我也不会赞成它.
我正在使用C#和WPF,我基本上想要一些切换按钮,并且只能同时选择其中一个.
我发现了另一个问题,但是那里显示的解决方案不起作用,我不知道为什么.
如果我尝试做在上面的问题中提到的ItemTemplate的ListBox不适用.我只是没有将切换按钮放入列表框,而是显示为"正常列表框".
我的切换按钮样式如下所示,包含在我的一个资源文件中:
<Style x:Key="ToggleButtonListBox" TargetType="{x:Type ListBox}">
<Setter Property="ListBox.ItemTemplate">
<Setter.Value>
<DataTemplate>
<ToggleButton Content="{Binding}"
IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ListBox.ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="0" />
</Style>
Run Code Online (Sandbox Code Playgroud)
我想直接在XAML代码中添加项目,所以我的代码看起来像
<ListBox Style="{StaticResource ToggleButtonListBox}">
<ListBoxItem>test1</ListBoxItem>
<ListBoxItem>test2</ListBoxItem>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
如何创建这样一组按钮?
我的代码在这里
if(c!=null)
{
c.moveToFirst();
String col = c.getString(2); //
check.setText(col);
check.setVisibility(0);
while(!c.isAfterLast())
{
String col1 = c.getString(1);
String col2 = c.getString(2);
String col3 = c.getString(3);
while(!c.isAfterLast())
{
TextView que1 = new TextView(this);
que1.setText(col1);
lymn.addView(que1);
if(col3.equals("Date"))
{
DatePicker dp = new DatePicker(this);
lymn.addView(dp);
break;
}
if(col3.equals("User Input"))
{
EditText ed = new EditText(this);
ed.setWidth(250);
lymn.addView(ed);
break;
}
if(col3.equals("YES/NO"))
{
yes1.setText("Yes");
no1.setText("NO");
rg1.addView(yes1);
rg1.addView(no1);
lymn.addView(rg1);
break;
}
if(col3.equals("High Average Low"))
{
High1.setText("High");
Avg1.setText("Average");
Low1.setText("Low");
rg2.addView(High1);
rg2.addView(Avg1);
rg2.addView(Low1);
lymn.addView(rg2);
break;
}
if(col3.equals("Excellent Good …Run Code Online (Sandbox Code Playgroud) 我有2个html单选按钮(由<br />标签分隔),其中文本包含在单选按钮下,而不是与左缩进对齐(由于它包含div的大小).文本包装不是问题,问题是它在单选按钮本身下不正确地包装,而不是与它上面的行中的文本对齐.我假设有人在级联中的某个地方设置了输入标签的样式.我没有详尽地搜索附加到此页面的所有样式,但文本是否应该像子弹列表一样自动正确包装?

如果没有,我将如何解决这个问题?我是否需要插入<br />标签,我希望线条断开,以便它们正确对齐?
谢谢!
我试图在Android中构建RadioGroup,默认情况下检查一个RadioButton.我想知道这是否可以通过XML而不是以编程方式完成.
以下代码片段似乎不起作用,因为我收到错误:
error: Error: No resource found that matches the given name (at 'checkedButton' with value '@id/rdb_positive')
Run Code Online (Sandbox Code Playgroud)
代码是:
<RadioGroup
style="@style/FormInputField"
android:orientation="vertical"
android:checkedButton="@id/rdb_positive"> <!-- Error on this line -->
<RadioButton
android:id="@+id/rdb_positive"
android:text="@string/answer_positive" />
<RadioButton
android:id="@+id/rdb_negative"
android:text="@string/answer_negative" />
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
它确实在某种程度上有意义,因为RadioButton的id是在RadioGroup中的属性设置之后定义的,但后来我想知道为什么有这样的属性可用.
当浏览器窗口变窄时,如何在文本换行时将单选按钮()或复选框[]及其标签保持在一起,这样我们就不会得到这样的结果:
[ ] pepperoni [ ] anchovies [ ] mushrooms [ ]
olives
Run Code Online (Sandbox Code Playgroud)
编辑以回应nowrap建议.谢谢你的建议.差不多了.它适用于Chrome,FF和Opera,但不适用于IE9.当页面CSS label {white-space: nowrap}和标记是:
<td>
<div>
<label>
<input type="radio" name="pizza" checked="true"
id="pepperoni" value="pepperoni" />pepperoni </label>
<label>
<input type="radio" name="pizza"
id="anchovies" value="anchovies" />anchovies </label>
<label>
<input type="radio" name="pizza"
id="mushrooms" value="mushrooms" />mushrooms </label>
<label>
<input type="radio" name="pizza"
id="olives" value="olives" />olives </label>
</div>
</td>
Run Code Online (Sandbox Code Playgroud)
在IE9中 TD变为固定宽度; 当浏览器窗口变窄时,TD不会收缩,我明白了:
( ] pepperoni ( ) anchovies ( ) mushrooms ( ) olives
Run Code Online (Sandbox Code Playgroud)
当我需要这个时:
( ) pepperoni ( ) anchovies
( …Run Code Online (Sandbox Code Playgroud) 我正在努力将radiobutton的价值发送到电子邮件.
我已编码2个radiobuttons,我已将第一个设置为默认选中.
表单和值工作,但不提交单选按钮值.
任何明智的话?
我有无线电输入,如果检查当前无线电,则通过点击无线电来取消检查状态.
这段代码:
<input type="radio" id="average_0" name="average" ng-model="checked" ng-change="false" value="500" class="ng-valid ng-dirty">
<input type="radio" id="average_1" name="average" ng-model="checked" ng-change="false" value="1000" class="ng-valid ng-dirty">
<input type="radio" id="average_2" name="average" ng-model="checked" ng-change="false" value="1500" class="ng-valid ng-dirty">
Run Code Online (Sandbox Code Playgroud)
不工作.
单选按钮仅在页面刷新时取消选中
<input type="radio" name="test">
1<input type="radio" name="test">2
<input type="button" id="btn" />
$("#btn").click(function(){
$(':radio').each(function () {
$(this).removeAttr('checked');
$('input[type="radio"]').attr('checked', false);
})
});
Run Code Online (Sandbox Code Playgroud)
我创造了一个小提琴 http://jsfiddle.net/8jKJc/220/
但它不能与Bootstrap一起使用
radio-button ×10
html ×3
javascript ×3
android ×2
css ×2
alignment ×1
angularjs ×1
checkbox ×1
flowlayout ×1
input ×1
jquery ×1
listbox ×1
php ×1
send ×1
togglebutton ×1
unchecked ×1
view ×1
wpf ×1
xaml ×1
xml ×1