【问题标题】:Dynamic radiobutton动态单选按钮
【发布时间】:2011-10-03 12:19:37
【问题描述】:

这是在 datalist 单选按钮中有 datalist 的 aspx 页面。这是单选按钮动态出现的地方 我想通过javascript检查所有单选按钮是否被选中,请帮助我

<asp:DataList  ID="TF_DataList" runat="server" RepeatDirection="Vertical" OnItemCreated="TF_Datalist_ItemCreated">
    <ItemTemplate>
        <table style="text-align:left;">
            <tr>
                <td valign="top" align="left" nowrap="nowrap">
                <asp:RadioButton ID="lbTrue" runat="server" GroupName="ans"  Text="T" onclick="Radcheck();"/>
                  <asp:RadioButton ID="lbFalse" runat="server" GroupName="ans" Text="F" onclick="Radcheck();"/>
</td>
                <td>&nbsp;&nbsp;</td>
                <td runat="server" id="AnswerContentTD" style="text-align: left">     
                    <asp:Label ID="lblAnswerText" runat="server" Text='<%# Eval("AnswerText")%>'></asp:Label>
                </td>
            </tr>  
        </table>
    </ItemTemplate>
     <ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:DataList>

【问题讨论】:

标签: asp.net radio-button


【解决方案1】:

使用Javascript

function ValidateDataListRadio() {
    var datalist = document.getElementById("<%= TF_DataList.ClientID %>");
    var items = datalist.getElementsByTagName('input');

    for (i = 0; i < items.length; i++) {
        if (items[i].type == "radio" && items[i].checked)) {
            return true;
        }
    }
    //alert("none selected");
    return false;
}

如果你使用的是 jQuery

标记略有变化。为 RadioButton 添加了一个 CssClass

<asp:RadioButton ID="lbTrue" runat="server" 
            ClassName="radiobutton"
            GroupName="ans"
            Text="T" />

代码

function ValidateDataListRadio() {
    return $(".radiobutton").is(':checked').length;
}

【讨论】:

    猜你喜欢
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多