gpt4 book ai didi

javascript - 隐藏未选中的单选按钮

转载 作者:技术小花猫 更新时间:2023-10-29 12:51:18 25 4
gpt4 key购买 nike

我想隐藏未选中的单选按钮,只显示选中的单选按钮:

<ul class="woof_list woof_list_radio">
<li >
<input type="radio" id="woof_72_55cb07a61800a" class="woof_radio_term" data-slug="elektronik" name="product_cat" value="72">
<label for="woof_72_55cb07a61800a">Elektronik <span>(812)</span></label>
</li>
<li >
<input type="radio" id="woof_113_55cb07a741fec" class="woof_radio_term" data-slug="pompa-air" name="product_cat" value="113" checked="checked">
<label for="woof_113_55cb07a741fec" checked="checked" style="font-weight: bold;">Pompa Air <span>(29)</span></label>
</li>
<li >
<input type="radio" id="woof_184_55cb07a7513ac" class="woof_radio_term" data-slug="brand" name="product_cat" value="184">
<label for="woof_184_55cb07a7513ac">Brand <span>(814)</span></label>
</li>
</ul>

这是我的 JavaScript:

$(document).ready(function(){

$("ul.woof_list").find("li").each(function(index){

$(this).find('input[checked="checked"]', ".woof_list");

$( this ).click( function( e ) {
e.preventDefault();
// by default, hide all li's
$( 'ul.woof_list li' ).toggle();
$( '.woof_is_closed' ).trigger('click');
// show only the selected li
$( this ).show();
});
console.log($(this).find('input[checked="checked"]', ".woof_list").val());

我得到了单选按钮的值,但我不知道该怎么办。

最佳答案

试试这个

$(document).ready(function () {
$(':radio').on('change', function () {
$(':radio').not($(this)).closest('li').hide();
});
});

https://jsfiddle.net/ds3Lfms7/1/

当你选中一个时,它会隐藏所有其他的

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

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