gpt4 book ai didi

javascript - JQuery .removeAttr ('required' ) 不适用于输入单选组

转载 作者:行者123 更新时间:2023-11-30 11:42:57 27 4
gpt4 key购买 nike

我想做的是当 $('input:radio[name="NeverWornRespbefore"]') 被选中时,我想从 radio 组 中删除所需的属性$('input:radio[name="eyeIrritation"]').

我的问题:为什么 .removeAttr('required') 或代码中的任何其他注释部分不会删除 required 标签?我如何让它工作?

谢谢。

<script>
//If user presses number 8 these radios don't have to be required
jQuery(document).ready(function () {

$('input:radio[name="NeverWornRespbefore"]').change(function () {
if ($(this).val() == 'Yes Never Worn one before') {

console.log("triggered");
//$('input:radio[name="eyeIrritation"]').removeAttr('required');​​​​​
//$('.eyeIrritation').each().attr("required", "false");
$('.eyeIrritation').removeAttr('required');
console.log($('input#eyeIrritation'));
}
});

});

这是我的 cshtml:

<tr>
<td><label class="col-xs-12 col-sm-6 col-md-8 control-label" for="employeeName">8. If you've used a respirator, have you ever had any of the following problems? </label><be><label class="col-xs-12 col-sm-6 col-md-8 control-label" for="employeeName">(If you've never used a respirator, check the following checkbox @Html.RadioButtonFor(m => m.NeverWornRespbefore, "Yes Never Worn one before", new { Value = "Yes Never Worn one before" }) and go to question 9)</label></td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td><label class="col-xs-12 col-sm-6 col-md-8 control-label" for="employeeName">a. eye irritation:</label></td>
<td>@Html.RadioButtonFor(m => m.eyeIrritation, "Yes", new { Value = "YES" , required = "true"})</td>
<td>@Html.RadioButtonFor(m => m.eyeIrritation, "No", new { Value = "NO" , required = "true"})</td>
</tr>

这是我完成的代码以及从评论中找到的答案

<script>
//If user presses number 8 these radios don't have to be required
jQuery(document).ready(function () {

$('input:radio[name="NeverWornRespbefore"]').change(function () {
if ($(this).val() == 'Yes Never Worn one before') {

console.log("Number never worn resp triggered");

$('input[name="eyeIrritation"]').removeAttr('required');
}
});

});

我选错了 radio 组。

最佳答案

您的选择器有误。尝试 $('input[name="eyeIrritation"]').removeAttr('required');

关于javascript - JQuery .removeAttr ('required' ) 不适用于输入单选组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41963956/

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