[英]JQuery .removeAttr('required') not working for input radio group
我想做的是當選擇$('input:radio[name="NeverWornRespbefore"]')
,我想從單選組$('input:radio[name="eyeIrritation"]')
刪除必需的屬性$('input:radio[name="eyeIrritation"]')
。
我的問題 :代碼中的.removeAttr('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>
這是我從COMMENTS找到的帶有ANSWER的完整代碼
<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');
}
});
});
我為廣播組選擇了錯誤的選擇器。
怎么樣
.prop('required', false);
您的選擇器有誤。 嘗試$('input[name="eyeIrritation"]').removeAttr('required');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.