如何将以下选择标签中的代码转换为单选按钮?

huangapple go评论70阅读模式
英文:

How can I convert the code in the following select tags into a radio button?

问题

可发货
建议

上述代码中有两个选项,我想用单选按钮显示这两个选项,而不是使用下拉框。在我的实验中,我所做的更改总是重叠在一起,无法实现动态效果。谢谢你的帮助。

英文:
<div class="form-group m-form__group row col-12">
<label for="example-text-input" class="col-3 col-form-label">Approval Status</label>
<div class="col-9">
    <select class="form-control m-input m-input--square" name="approvalstatus" required>
        @if ((int)Model.PARAMETER.APPROVALSTATUS == 4)
        {
            <option selected value="4">Shipable</option>
        }
        else
        {
            <option value="4">Shipable</option>
        }
        @if ((int)Model.PARAMETER.APPROVALSTATUS == 1)
        {
            <option selected value="1">Suggestion</option>
        }
        else
        {
            <option value="1">Suggestion</option>
        }
    </select>
</div>

</div>

> There are two options in the above code, I want to show these two options with radio button, not with select. In my own experiments, the changes I made always overlapped and I could not make it dynamic. Thanks for your help.

答案1

得分: 2

我认为这是您期望的内容,

<div class="form-group m-form__group row col-12">
    <label for="example-text-input" class="col-3 col-form-label">Approval Status</label>
    <div class="col-9">
        <label class="radio-inline">
            <input type="radio" name="approvalstatus" value="4" 
                @if ((int)Model.PARAMETER.APPROVALSTATUS == 4)
                {
                    checked
                }
            > Shipable
        </label>
        <label class="radio-inline">
            <input type="radio" name="approvalstatus" value="1" 
                @if ((int)Model.PARAMETER.APPROVALSTATUS == 1)
                {
                    checked
                }
            > Suggestion
        </label>
    </div>
</div>

更新:如Hans建议您这样做,

<input type="radio" name="approvalstatus" value="4" checked=@((int)Model.PARAMETER.APPROVALSTATUS == 4) required> Shipable
英文:

I think this is what you are expecting,

&lt;div class=&quot;form-group m-form__group row col-12&quot;&gt;
&lt;label for=&quot;example-text-input&quot; class=&quot;col-3 col-form-label&quot;&gt;Approval Status&lt;/label&gt;
&lt;div class=&quot;col-9&quot;&gt;
    &lt;label class=&quot;radio-inline&quot;&gt;
        &lt;input type=&quot;radio&quot; name=&quot;approvalstatus&quot; value=&quot;4&quot; 
            @if ((int)Model.PARAMETER.APPROVALSTATUS == 4)
            {
                checked
            }
        &gt; Shipable
    &lt;/label&gt;
    &lt;label class=&quot;radio-inline&quot;&gt;
        &lt;input type=&quot;radio&quot; name=&quot;approvalstatus&quot; value=&quot;1&quot; 
            @if ((int)Model.PARAMETER.APPROVALSTATUS == 1)
            {
                checked
            }
        &gt; Suggestion
    &lt;/label&gt;
&lt;/div&gt;

updated: as Hans suggest you do it as,

&lt;input type=&quot;radio&quot; name=&quot;approvalstatus&quot; value=&quot;4&quot; checked=@((int)Model.PARAMETER.APPROVALSTATUS == 4) required&gt; Shipable

huangapple
  • 本文由 发表于 2023年1月9日 18:59:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056307.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定