gpt4 book ai didi

如果单选按钮被选中,则 jQuery addClass

转载 作者:行者123 更新时间:2023-12-01 02:23:45 25 4
gpt4 key购买 nike

谁能帮我解决这个问题吗?

$(document).ready(function() {
if(
$("input.check").is(":checked")){
$(this).parent().addClass("question-box-active");
}
});

仅当选中时,我才尝试将一个类(question-box-active)添加到 .check (单选按钮)的父级。如果我使用警报进行测试,效果很好,但我无法添加该类。

感谢大家的帮助。

更新:这是表单的 HTML。我只复制了 48 个 div 中的 3 个。正如您可能猜测的那样,如果单选按钮已在页面加载时选中,我将尝试向问题框中添加一个类。到目前为止还没有运气。

<div class="question-box">
<input class="check" type="checkbox" name="question-1" value="1" <?php if(isset($_POST['question-1'])) echo "checked"; ?> />
<span class="question">1. Save a rainforest or grow organic vegetables</span>
</div>

<div class="question-box alt">
<input class="check" type="checkbox" name="question-2" value="1" <?php if(isset($_POST['question-2'])) echo "checked"; ?> />
<span class="question">2. Solve complicated math problems</span>
</div>

<div class="question-box">
<input class="check" type="checkbox" name="question-3" value="1" <?php if(isset($_POST['question-3'])) echo "checked"; ?> />
<span class="question">3. Act in a movie, play, or television show</span>
</div>

最佳答案

尝试类似的事情

$('input.check').is(':checked').each(function() { 
$(this).parent().addClass('question-box-active');
});

关于如果单选按钮被选中,则 jQuery addClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7973868/

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