gpt4 book ai didi

javascript - 选中的单选按钮显示一个 div

转载 作者:行者123 更新时间:2023-11-28 13:50:47 25 4
gpt4 key购买 nike

我有这个标记我的网页之一,

<div class="radio-spoof">
<input type="radio" name="enquiry" value="General enquiry" class="radio"/>
<div class="checked"></div>
</div>
<label for="general_enquiry">General enquiry</label>
<div class="radio-spoof">
<input type="radio" name="enquiry" value="Request a brochure" class="radio" checked="true"/>
<div class="checked"></div>
</div>
<label for="request_a_brochure">Request a brochure</label>

基本上我正在做的是试图欺骗一些单选按钮,这样我就可以拥有好看的单选按钮,当选中单选按钮时我想显示 .checked设置为 display:none默认情况下。我需要在 DOMReady 上检查选中的单选按钮,当单击单选按钮时,当前我有此页面,但它似乎没有正确选择 .checked div。

if($('input[type=radio]:checked')) {<br/>
console.log("!");<br/>
$(this).parent().children('div').show();<br/>
}

我希望上面的代码选择父级单选按钮,然后查找子 div (.checked) 并显示它。我错了吗?`

最佳答案

$(function(){
$(':radio').change(function(){
var $this = $(this);
console.log($this);
$(':radio[name='+this.name+']').next().hide();
if($this.is(':checked')){
$this.next('.checked').show();
}
});
});

关于javascript - 选中的单选按钮显示一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com