作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要根据选中的单选按钮显示不同的 div。我已经通过使用更改事件方法完成了它。但是我需要在加载页面时通过查看选中的按钮来完成它。
$('#id_radio1').click(function () {
$('#div2').hide('fast');
$('#div1').show('fast');
});
单选按钮是
<div class="col-md-4">
<label>
<input type="radio" name="sublink" id="id_radio2" value="0" <?php if($announcements_details['detail_type']=="0") echo' checked="checked"'?> > Add attachment to title</input>
</label>
</div>
<div class="col-md-4">
<label>
<input type="radio" name="sublink" id="id_radio1" value="1" <?php if($announcements_details['detail_type']=="1") echo' checked="checked"'?> > Add new sublinks</input>
</label>
</div>
<div class="col-md-4">
<label>
<input type="radio" name="sublink" id="id_radio3" value="2" <?php if($announcements_details['detail_type']=="2") echo' checked="checked"'?>> None
</label>
</div>
帮我解决这个问题
最佳答案
JS 查询
在页面加载时检查 radio 。
$("input[name=sublink]").each(function(index, elem){
if($(this).prop("checked")){
console.log("radio (with checked) has value: "+elem.value);
if(elem.value == "0"){
// LOGIC FOR SHOW/HIDE DIV HERE
} else if(elem.value == "1"){
// LOGIC FOR SHOW/HIDE DIV HERE
} else if(elem.value == "2"){
// LOGIC FOR SHOW/HIDE DIV HERE
}
}
});
.....
如果你需要这个。单击输入 radio 时检查 radio 。
$("input[name=sublink]").on("change", function(){
switch(this.value){
case "0":
console.log("radio with value 0");
// LOGIC FOR SHOW/HIDE DIV HERE
break;
case "1":
console.log("radio with value 1");
// LOGIC FOR SHOW/HIDE DIV HERE
break;
case "2":
console.log("radio with value 2");
// LOGIC FOR SHOW/HIDE DIV HERE
break;
default:
console.log("default");
}
});
关于javascript - 通过使用 jquery 检查选中哪个单选按钮来执行事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41563704/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!