简体   繁体   English

单击标签时单选按钮的空值

[英]Radio button empty value when clicking on label

I am having some odd behavior with a radio button , as you can see in the GIF attached. 我在单选按钮上有一些奇怪的行为,如附件GIF所示。

When i click on the label the selected value gets cleared and the radio buttons will become empty with none of the values checked 当我单击标签时,所选值将被清除,单选按钮将变为空,且未选中任何值

I could not find the cause of the issue . 我找不到问题的原因。

I am just using basic radio buttons 我只是使用基本的单选按钮

` `

<tr>
    <td style="padding-left: 15px">@Html.Raw(Dashboard.ResourcesLanguage.Language.admin)</td>
    <td class="Admin-class"></td>
    <td><input class="checkbox" type="radio"    id="radioYes"  name="radioAdmin" value="Yes" /><label for="radioYes">@Html.Raw(Dashboard.ResourcesLanguage.Language.yes)</label></td>
    <td><input class="checkbox" type="radio"    id="radioNo"   name="radioAdmin" value="No" checked /><label for="radioNo">@Html.Raw(Dashboard.ResourcesLanguage.Language.no)</label></td>
    <td><input class="checkbox" type="checkbox" id="error-log" name="ErrorLog" disabled>@Html.Raw(Dashboard.ResourcesLanguage.Language.errorLog)</td>
</tr>    
<tr>
    <td style="padding-left: 15px">@Html.Raw(Dashboard.ResourcesLanguage.Language.auditor)</td>
    <td class="Auditor-class"></td>
    <td><input class="checkbox" type="radio" id="radioYesAudit" name="radioAuditor" value="Yes" /><label for="radioYes">@Html.Raw(Dashboard.ResourcesLanguage.Language.yes)</label></td>
    <td><input class="checkbox" type="radio" id="radioNoAudit" name="radioAuditor" value="No" checked /><label for="radioNo">@Html.Raw(Dashboard.ResourcesLanguage.Language.no)</label></td>
</tr>

奇怪的行为

You use the same label for in the radio buttons below the checkboxes. 您可以在复选框下方的单选按钮中使用相同的label for It should be 它应该是

<input class="checkbox" type="radio" id="radioYesAudit" name="radioAuditor" value="Yes" />
<label for="radioYesAudit">@Html.Raw(Dashboard.ResourcesLanguage.Language.yes)</label>

Not as it is now 不是现在

<input class="checkbox" type="radio" id="radioYesAudit" name="radioAuditor" value="Yes" />
<label for="radioYes">@Html.Raw(Dashboard.ResourcesLanguage.Language.yes)</label>

It is the same for the radioNoAudit radio button radioNoAudit单选按钮相同

The problem is that your Label for Radio YES, so that's why you are not seeing the radio button filled in the right place. 问题是您的Radio标签为YES,所以这就是为什么您未在正确的位置看到单选按钮的原因。

<td><input class="checkbox" type="radio" id="radioYesAudit" name="radioAuditor" value="Yes" /><label for="radioYesAudit">@Html.Raw(Dashboard.ResourcesLanguage.Language.yes)</label></td>
                <td><input class="checkbox" type="radio" id="radioNoAudit" name="radioAuditor" value="No" checked /><label for="radioNoAudit">@Html.Raw(Dashboard.ResourcesLanguage.Language.no)</label></td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM