我是javascript和jQuery的新手.在我的HTML有2个单选按钮和一个div.如果我检查第一个单选按钮,我想显示div,否则我希望它被隐藏
所以:如果选中了#watch-me单选按钮 - > div#show-me是可见的.如果未选中单选按钮#watch-me(未选中或未选中第二个) - > div#show-me隐藏.
这是我到目前为止所拥有的.
<form id='form-id'>
<input id='watch-me' name='test' type='radio' /> Show Div<br />
<input name='test' type='radio' /><br />
<input name='test' type='radio' />
</form>
<div id='show-me' style='display:none'>Hello</div>
Run Code Online (Sandbox Code Playgroud)
和JS:
$(document).ready(function () {
$("#watch-me").click(function() {
$("#show-me:hidden").show('slow');
});
$("#watch-me").click(function(){
if($('watch-me').prop('checked')===false) {
$('#show-me').hide();}
});
});
Run Code Online (Sandbox Code Playgroud)
我该如何更改脚本来实现这一目标?
我的表单目前包含以下代码:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<label for="opt-0"><input type="radio" name="opt" id="opt-0" checked>Option 0</label>
<label for="opt-1"><input type="radio" name="opt" id="opt-1">Option 1</label>
<label for="opt-2"><input type="radio" name="opt" id="opt-2">Option 2</label>Run Code Online (Sandbox Code Playgroud)
我没有将单选按钮显示为单选按钮,而是让它们看起来像常规按钮,如下所示:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn btn-primary">Option 0</button>
<button class="btn btn-default">Option 1</button>
<button class="btn btn-default">Option 2</button>Run Code Online (Sandbox Code Playgroud)
我有收音机,我想让它们看起来像可切换的按钮.我怎么能用Bootstrap做到这一点?
我有两个单选按钮的组件 HTML look like
<div class="btn-group" id="ProfitCodes">
<div class="radio">
<label>
<input type="radio"
class="radio-inline"
value="1"
[checked]="model.ForeignCompany.ProfitCode === 1"
[(ngModel)]="model.ForeignCompany.ProfitCode"
id="point1"
name="ProfitCode"><small>description</small>
</label>
</div>
<div class="radio">
<label>
<input type="radio"
class="radio-inline"
[(ngModel)]="model.ForeignCompany.ProfitCode"
[checked]="model.ForeignCompany.ProfitCode === 2"
value="2"
id="point2"
name="ProfitCode"><small>description</small>
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
当我单击保存并将模型发送到服务器时,我看到服务器端的单选按钮的有效选择值.并且此值存储在数据库中而没有错误.但是在绑定数据后,具有适当值的radiobutton不会受到影响.在devTools中,我看到了第一个单选按钮:
<input class="radio-inline ng-untouched ng-pristine ng-valid" id="point1" name="ProfitCode" title="asdasda" type="radio" value="1" ng-reflect-name="ProfitCode" ng-reflect-value="1" ng-reflect-model="2" ng-reflect-checked="false">
Run Code Online (Sandbox Code Playgroud)
第二个单选按钮:
<input class="radio-inline ng-untouched ng-pristine ng-valid" id="point2" name="ProfitCode" title="asd" type="radio" value="2" ng-reflect-name="ProfitCode" ng-reflect-value="2" ng-reflect-model="2" ng-reflect-checked="true">
Run Code Online (Sandbox Code Playgroud)
我看到角度改变了属性并等待第二个单选按钮被检查.但这不会发生.我究竟做错了什么?
在Linux上,希望有一组互斥的菜单项,并且当前选择的菜单项由单选按钮而不是复选框指定.
有没有办法在Qt v4.4.3中轻松完成这项工作?
我需要为一组单选按钮注册一个处理程序.我正在使用JQuery,并希望它的.change方法能够实现这一点.但是,我没有经历过期望的行为.
这是我写的一个示例片段.遗憾的是,"radioValueChanged"仅在初始加载时调用.选择true/false不会触发处理程序.
<html>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<form id="myForm">
<div id="Question1Wrapper">
<div>
<input type="radio" name="controlQuestion" id="valueFalse" value="0" />
<label for="valueFalse">
False</label>
</div>
<div>
<input type="radio" name="controlQuestion" id="valueTrue" value="1" />
<label for="valueTrue">
True</label>
</div>
</div>
<div id="Question2Wrapper">
<div>
<label for="optionalTextBox">
This is only visible when the above is true</label>
<input type="text" name="optionalTextBox" id="optionalTextBox" value="" />
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function ()
{
$("#controlQuestion").change(radioValueChanged('controlQuestion'));
})
function radioValueChanged(radioName)
{
radioValue = $('input[name=' + radioName + ']:checked', '#myForm').val();
alert(radioValue);
if(radioValue == 'undefined' || …Run Code Online (Sandbox Code Playgroud) 我一直在努力解决RadioButton的程序性检查问题,RadioButton位于RadioGroup中.看起来单个check()调用会引发三个事件 - 一个用于第一个RadioButton,两个用于第二个,这是我的目标.同时点击界面中的第二个RadioButton只会出现一个事件,这是正确的.
那么,有没有办法避免多次事件提升?
public class RadiogroupActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RadioGroup r = (RadioGroup) findViewById(R.id.radioGroup1);
RadioButton b = (RadioButton) findViewById(R.id.radio1);
r.setOnCheckedChangeListener(onPromobuttonsClick);
r.check(R.id.radio1);
}
private OnCheckedChangeListener onPromobuttonsClick = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.d("x", "x");
}
};
}
Run Code Online (Sandbox Code Playgroud) 是否有一种简单的方法在RadioButtons内部添加分隔符RadioGroup?我尝试过使用dividerxml属性,但似乎没有用.如果它是相关的RadioGroup,我的布局中不包含任何子视图; 我正在以RadioButtons编程方式添加.
编辑:问题解决了.您可以在xml中添加RadioButton内部视图RadioGroup.在我的情况下,您也可以以编程方式执行此操作,但请注意您的布局参数.Akki有正确的想法,这对我有用:
for (int i = 0; i < items.size(); i++) {
if (i > 0) {
// add a divider with height of 1 pixel
View v = new View(this);
v.setLayoutParams(new RadioGroup.LayoutParams(LayoutParams.MATCH_PARENT, 1));
v.setBackgroundColor(android.R.color.darker_gray);
mRadioGroup.addView(v);
}
RadioButton rb = new RadioButton(this);
/* set other properties ... */
mRadioGroup.addView(rb);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试以编程方式将一组RadioButtons添加到RadioGroup,如下所示:
for (int i = 0; i < RANGE; i++) {
RadioButton button = new RadioButton(this);
button.setId(i);
button.setText(Integer.toString(i));
button.setChecked(i == currentHours); // Select button with same index as currently selected number of hours
button.setButtonDrawable(Color.TRANSPARENT);
button.setBackgroundResource(R.drawable.selector);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
((RadioGroup)view.getParent()).check(view.getId());
currentHours = view.getId();
}
});
radioGroupChild.addView(button);
}
Run Code Online (Sandbox Code Playgroud)
我需要将drawable按钮设置为null(我只想在我的背景上添加文本).在XML中手动执行此操作android:button="@null"非常好,但我不想对每个单选按钮进行硬编码.我尝试过这样做,button.setButtonDrawable(null)但它没有改变任何东西.
任何帮助是极大的赞赏!
我可以成功调出一个铃声选择器并使用以下代码获得结果uri ...
selsound_button.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_ALARM);
startActivityForResult( intent, 999);
}
});
Run Code Online (Sandbox Code Playgroud)
...但我没有弄清楚如何做到以下几点:
鉴于我已经知道当前的uri,我希望告诉选择器当前选择它以便它可以突出显示正确的单选按钮.目前,在我按下其中一个之前,根本没有选择任何无线电按钮.
Bootstrap的JavaScript页面显示了一些很好用的按钮来设置复选框和无线电字段的样式.例如,对于复选框,我可能会写
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="checkbox"> Option 1
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
但是,库实际上并不会更改基础<input>字段的值- 它只会更改<label>字段是否具有类active.我原以为它会改变checked复选框上的属性.显然我不只是错误配置 - 这是Bootstrap网站上的示例工作方式.
这实际上是预期的行为吗?如果是这样,它似乎相当无用,因为人们想要使用复选框字段.如果没有,我如何正确配置Bootstrap复选框/单选按钮?
radio-button ×10
android ×4
radio-group ×4
html ×3
css ×2
javascript ×2
jquery ×2
angular ×1
checkbox ×1
data-binding ×1
divider ×1
menu ×1
onchange ×1
qt ×1