如果选中了单选按钮,则显示div [英] If Radio button checked show div
本文介绍了如果选中了单选按钮,则显示div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面有HTML代码:
I have HTML CODE below:
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="ABC"){
$(".Box").hide('slow');
}
if($(this).attr("value")=="PQR"){
$(".Box").show('slow');
}
});
<table>
<tr>
<td align="left" height="45">
<input type="radio" class="radioBtn" name="Radio"
id="Radio" value="ABC" required>
ABC
<input class="radioBtn" type="radio" name="Radio"
id="Radio" value="PQR" required>
PQR
<div class="Box" style="display:none">Text</div>
</td>
</tr>
</table>
以上所有代码都可以正常工作&适当地.但是我的问题是,当我默认选中PQR时,Box div应该通过单击单选按钮显示.我的代码有什么错误或需要对其进行哪些更改.
All above code is working fine & properly. But my issue is that when I checked by default PQR then the Box div should display with clicking radio button. What wrong in my code or what changes it need..??
推荐答案
您需要trigger
click
$(document).ready(function () {
$('input[type="radio"]').click(function () {
if ($(this).attr("value") == "ABC") {
$(".Box").hide('slow');
}
if ($(this).attr("value") == "PQR") {
$(".Box").show('slow');
}
});
$('input[type="radio"]').trigger('click'); // trigger the event
});
DEMO
这篇关于如果选中了单选按钮,则显示div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文