例子
单选框radio(不用name和value做判断判断条件)。
点击“其他”时候,后面的input填写框显示。
点击“中国大陆”,后面input填写框不显示。
代码
html
代码,默认选择“中国大陆”,输入框隐藏display: none;
<div class="a">
<div>
注册地域:
</div>
<div>
<label><input type="radio" checked>中国大陆</label>
<label><input type="radio">其他</label>
<input class="isAreaToggle" type="text"
style="height: 30px;width: 250px; display: none;" />
</div>
</div>
jQuery
代码
$('.a').click(function (e) {
if (e.target === $(this).find("input[type=radio]")[0]) {
$('.isAreaToggle').hide();
} else if (e.target === $(this).find("input[type=radio]")[1]) {
$('.isAreaToggle').show();
}
});
ps:
复选框直接用click事件就最简短:
复选框"其他"代码:
// html
<div style="display: flex;">
<label style="font-weight: normal;">
<input type="checkbox" name="RewarType" class="checkbox-other"/>
其他
</label>
<input class="k-form-control other-input"
style="display: none;width: 50%;margin-left:15px;"
type="text" name="RewarType" value="" />
</div>
// jQuery
$(".checkbox-other").click(function() {
$('.other-input').toggle();
});