【问题标题】:selecting multiple Radio buttons with the same name选择具有相同名称的多个单选按钮
【发布时间】:2014-04-30 20:57:37
【问题描述】:

下面代码中的单选按钮具有相同的名称,但我仍然可以选择多个按钮 我不会让它发生的。

<asp:ListView ID="BuyM" runat="server" DataKeyNames="kod" >
    <LayoutTemplate>

        <table dir="rtl" style="border:1px solid black;background-color:#E6CCFF;" >
            <tr class="header">
                <td>dsg</td>
                <td>dfg</td>
                <td>dfg</td>
                <td>fgd</td>
                <td>dfg</td>
            </tr>
            <tr><asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder></tr>
        </table>

    </LayoutTemplate>
    <ItemTemplate>
        <tr class="row">
            <th>
                   <input type="radio" id="rb" runat="server" name="rb" value='<%# Eval("kod") %>' />
            </th>
            <th>
                <%# Eval("kod") %>
            </th>
            <th>
                <%# Eval("nameE") %>
            </th>
            <th>

                <%# Eval("Sk") %>
            </th>
            <th>
                <%# Eval("groupN") %>
            </th>
        </tr>
    </ItemTemplate>
    <AlternatingItemTemplate>
        <tr class="alterRow">
            <th>
                <input type="radio" id="rb" runat="server"  name="rb" value='<%# Eval("kod") %>' />
            </th>
            <th>
                <%# Eval("kod") %>
            </th>
            <th>
                <%# Eval("nameE") %>
            </th>
            <th>
                <%# Eval("Sk") %>
            </th>
            <th>
                <%# Eval("groupN") %>
            </th>
        </tr>
    </AlternatingItemTemplate>
    <EmptyDataTemplate>
        no records found
    </EmptyDataTemplate>
</asp:ListView></div>

我该如何修复它?(在我添加 runat="server" 和值之前它工作正常)

【问题讨论】:

    标签: html forms listview radio-button


    【解决方案1】:

    不要对多个元素使用相同的 ID。名称可以相同,但 ID 不能相同。还要验证单选按钮是否包含在同一个表单中。

    【讨论】:

    • 单选按钮包含在相同的表单中。此外,我尝试更改其中一个单选按钮的 ID,但它也没有帮助,我仍然可以选择多个单选按钮。
    猜你喜欢
    • 2015-08-27
    • 1970-01-01
    • 2012-06-09
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多