Javascript 如果选中单选按钮,则在Codeigniter中显示div
我正在尝试创建一个用户表单,我被困在其中,因为我希望如果选中一个单选按钮,然后显示一个div。我不能这样做,因为我在javascript方面有点弱。请在下面找到我的代码。 我的按钮是Javascript 如果选中单选按钮,则在Codeigniter中显示div,javascript,php,jquery,twitter-bootstrap,codeigniter,Javascript,Php,Jquery,Twitter Bootstrap,Codeigniter,我正在尝试创建一个用户表单,我被困在其中,因为我希望如果选中一个单选按钮,然后显示一个div。我不能这样做,因为我在javascript方面有点弱。请在下面找到我的代码。 我的按钮是 <label> <input type="radio" name="groups[]" value="6"> Head of Distribution Sales </label> 分销销售主管 选择按钮后,我想显示这个div <div class="for
<label>
<input type="radio" name="groups[]" value="6"> Head of Distribution Sales
</label>
分销销售主管
选择按钮后,我想显示这个div
<div class="form-group">
<label class="col-md-3 control-label">Regions</label>
<div class="col-md-9">
<div class="checkbox-list">
<label>
<input type="checkbox" name="groups[]" value="43"> Dhaka North
</label>
<label>
<input type="checkbox" name="groups[]" value="44"> Dhaka South
</label>
<label>
<input type="checkbox" name="groups[]" value="45"> Comilla
</label>
<label>
<input type="checkbox" name="groups[]" value="46"> Chittagong
</label>
<label>
<input type="checkbox" name="groups[]" value="47"> Khulna
</label>
<label>
<input type="checkbox" name="groups[]" value="48"> Mymensingh
</label>
<label>
<input type="checkbox" name="groups[]" value="49"> Sylhet
</label>
<label>
<input type="checkbox" name="groups[]" value="50"> Rangpur
</label>
<label>
<input type="checkbox" name="groups[]" value="51"> Bogra
</label>
<label>
<input type="checkbox" name="groups[]" value="52"> Barisal
</label>
</div>
</div>
</div>
区域
达卡北部
达卡南部
科米拉
吉大港
库尔纳
迈门辛格
西尔赫特
朗普
博格拉
巴里萨尔
请帮我解决这个问题。使用jQuery:
$(document).ready(function() {
$('input[type="radio"]').click(function() {
if($(this).attr('id') == 'your input id') {
$('#div id').show();
}
else {
$('#div id').hide();
}
});
});
要实现这一点,您必须在HTML中进行以下更改,并将jquery代码作为代码段实现
style=“display:none”
$(“输入[type='radio'][name='groups[]']”)。在(“更改”,函数()上){
如果($(this).is(':checked')){
$(“#displayDS”).show();
}否则{
$(“#displayDS”).hide();
}
});代码>
分销销售主管
区域
达卡北部
达卡南部
科米拉
吉大港
库尔纳
迈门辛格
西尔赫特
朗普
博格拉
巴里萨尔
我向simplifier添加了一些ID
// HTML
<label>
<input type="radio" id="myRadio" name="groups[]" value="6"> Head of Distribution Sales
</label>
<div id="yourDiv" class="form-group" style="display:none;"> [... checkboxes ...] </div>
// JS
document.getElementById('myRadio').addEventListener('change', function(){
document.getElementById('yourDiv').style.display = this.checked ? 'block' : 'none';
});
分销销售主管
区域
达卡北部
达卡南部
科米拉
吉大港
库尔纳
迈门辛格
西尔赫特
朗普
博格拉
巴里萨尔
分销销售主管
如果没有其他单选按钮,请先显示您所尝试的jquery代码?或者它是唯一的一个?您需要给出完整的HTML结构,如果没有更多的单选按钮,那么根据这一点,只有我们给出了解决方案。谢谢先生。你救了我一天@Rahul PatelYou是受欢迎的朋友。。如果我的回答对你有帮助,请接受并投票,这样其他人也会觉得它有帮助。