JQuery .removeAttr(' required')不适用于输入无线电组

时间:2017-01-31 17:35:05

标签: javascript jquery html razor

我要做的是当选择Private Sub yearGroup_GotFocus2() Dim nowDate As Date Dim dob As Date Dim dobMonth As Integer Dim dobYear As Integer Dim NCY As Integer Dim currentlyInSchool As Boolean Dim schoolYear As Long Dim schoolGrade As Long nowDate = Date nowYear = Year(nowDate) dob = DateValue("Feb 15, 2000") dobMonth = Month(dob) dobYear = Year(dob) NCY = nowYear - dobYear abc = 123 ' First find out the current school year. ' School year runs from August to May If Month(nowDate) <= 5 Then schoolYear = Year(nowDate) - 1 Else schoolYear = Year(nowDate) End If Debug.Print "School year: " & schoolYear & "/" & Mid(CStr(schoolYear + 1), 3, 2) If Month(dob) < 8 Then schoolGrade = 1 Else schoolGrade = 0 End If schoolGrade = schoolGrade + (schoolYear - (Year(dob) + 5)) Debug.Print "Pupil Grade: " & schoolGrade End Sub 时,我想从广播组$('input:radio[name="NeverWornRespbefore"]')中删除所需的属性。

我的问题:为什么代码中的$('input:radio[name="eyeIrritation"]')或其他任何评论部分都不会删除所需的标记?我如何让这个工作?

谢谢。

.removeAttr('required')

这是我的cshtml:

<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'));
        }
    });

});

这是我在COMMENTS中找到答案的完成代码

<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>

我的收音机组选择错了。

2 个答案:

答案 0 :(得分:1)

怎么样

.prop('required', false);

答案 1 :(得分:1)

你的选择器错了。试试$('input[name="eyeIrritation"]').removeAttr('required');

相关问题