使用javascript隐藏/显示单选按钮列表项

Hide/Show Radio Button List Item using javascript

本文关键字:单选按钮 列表 显示 javascript 隐藏 使用      更新时间:2023-09-26

我有一个下拉列表,比如ddlTest,其中有Opt1, Opt2作为项。在同一页面上,我有一个单选按钮列表,列表项为rblItem1、rblItem2和rblItem3。现在,如果用户在下拉列表中选择了Opt2,那么我应该隐藏rblItem3,或者对于选择的任何其他选项,我应该在单选按钮列表中显示rblItem3。

你能让我知道如果它是可能的,以及如何使用javascript做到这一点。

<table>
    <tr>
        <td>
                <asp:RadioButtonList ID="radiobuttonlist1" runat="Server" RepeatLayout="flow" RepeatDirection="horizontal">
                         <asp:ListItem Text="Radio 1" Value="1" Selected="True"></asp:ListItem>    
                           <asp:ListItem Text="Radio 2" Value="2"></asp:ListItem>
                             <asp:ListItem Text="Radio 3" Value="3"></asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                                <td>
                                    <input type="button" value="Submit" onclick="GetRadioButtonValue('<%= radiobuttonlist1.ClientID %>')" />
                                </td>
                            </tr>
                        </table>
Javascript代码:-
<script language="javascript" type="text/javascript">
        // Get radio button list value
        function GetRadioButtonValue(id)
        {
            var radio = document.getElementsByName(id);
            for (var j = 0; j < radio.length; j++)
            {
                if (radio[j].checked)
                   //make hide the Item
            }
        }
</script>