javascript - 单击单选按钮时显示文本框。我该怎么做呢?

标签 javascript jquery asp.net vb.net

我们有一个在线投票箱,为选民提供选择领导人的选项。

选民可以选择任何列出的候选人。

或者他们可以写一个自己选择的候选人。

为此,我们希望在选中“写入候选人”单选按钮后向选民显示一个文本框。

我该怎么做?

下面的 RadiobuttonList 代码是从数据库动态填充的。

 <asp:RadioButtonList ID="RadioButtonList1" runat="server" align="center" style="width:20px;height:20px;zoom:150%; white-space:nowrap;">
</asp:RadioButtonList>

Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim anstype As HiddenField = e.Item.FindControl("HiddenField1")
        'Dim positionid As Label = e.Item.FindControl("Label3")
        Dim positionid As HiddenField = e.Item.FindControl("HiddenField2")
        Dim rbl As RadioButtonList = e.Item.FindControl("RadioButtonList1")
        Dim cbl As CheckBoxList = e.Item.FindControl("CheckBoxList1")
        Dim txt As TextBox = e.Item.FindControl("TextBox1")
        Dim ds As DataSet = GetDataSet(positionid.Value)
        Select Case anstype.Value
            Case "S"
                rbl.Visible = True
                cbl.Visible = False
                txt.Visible = False
                rbl.DataSource = ds
                rbl.DataTextField = "CandidateName"
                rbl.DataValueField = "CandidateId"
                rbl.DataBind()
            Case "M"
                rbl.Visible = False
                cbl.Visible = True
                txt.Visible = False
                cbl.DataSource = ds
                cbl.DataTextField = "CandidateName"
                cbl.DataValueField = "CandidateId"
                cbl.DataBind()
        End Select
    End If
End Sub

//查看源代码

<tr>
<td><input id="DataList1_RadioButtonList1_5_2_5" type="radio" name="DataList1$ctl06$RadioButtonList1" value="27" /><label for="DataList1_RadioButtonList1_5_2_5">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl06$writeIn" type="text" id="DataList1_writeIn_5" />


<tr>
<td><input id="DataList1_RadioButtonList1_6_2_6" type="radio" name="DataList1$ctl07$RadioButtonList1" value="28" /><label for="DataList1_RadioButtonList1_6_2_6">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl07$writeIn" type="text" id="DataList1_writeIn_6" />

<tr>
<td><input id="DataList1_RadioButtonList1_7_1_7" type="radio" name="DataList1$ctl08$RadioButtonList1" value="29" /><label for="DataList1_RadioButtonList1_7_1_7">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl08$writeIn" type="text" id="DataList1_writeIn_7" />

<tr>
<td><input id="DataList1_RadioButtonList1_8_4_8" type="radio" name="DataList1$ctl09$RadioButtonList1" value="30" /><label for="DataList1_RadioButtonList1_8_4_8">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl09$writeIn" type="text" id="DataList1_writeIn_8" />

<tr>
<td><input id="DataList1_RadioButtonList1_9_1_9" type="radio" name="DataList1$ctl10$RadioButtonList1" value="31" /><label for="DataList1_RadioButtonList1_9_1_9">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl10$writeIn" type="text" id="DataList1_writeIn_9" />

<tr>
<td><input id="DataList1_RadioButtonList1_10_1_10" type="radio" name="DataList1$ctl11$RadioButtonList1" value="32" /><label for="DataList1_RadioButtonList1_10_1_10">Write In Candidate</label></td>
</tr>   
 <input name="DataList1$ctl11$writeIn" type="text" id="DataList1_writeIn_10" />

以下是屏幕截图。

enter image description here

最佳答案

 protected void RadioButtonList1_CheckedChanged(object sender, EventArgs e)
    {
        if (RadioButton1.Checked)
        {
            //if Radio Button is Checked the Textbox is visible
            TextBox.Visible = true;
        }
        else if (!RadioButton1.Checked)
        {
          //if Radio Button is not Checked the Textbox is In-visible
            TextBox.Visible = false;
        }
     ...
//and show on for other checkbox

关于javascript - 单击单选按钮时显示文本框。我该怎么做呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22433137/

相关文章:

javascript - Firefox 中具有可调整大小列的 JQuery UI 表性能问题

javascript - 为什么 jQuery 对我的所有列表元素应用点击阻止

javascript - 将自定义下一张幻灯片按钮添加到 Unslider 脚本

c# - Visual Studio - 无法运行任何项目 : application was unable to start correctly (0xc0000142)

javascript - 如何将 div 元素放入 jQuery Slider 中,显示至少 5 个元素,并使用左右 slider 查看更多元素?

asp.net - 如何理解 Visual Studio 2008 中的动态 HTML?

javascript - 从 meteor 和 Cordova 上传视频

javascript - AngularJS 不显示值

javascript - 如何访问 p5.js Canvas 上的实时草图图像?

javascript - 如何在 jqGrid 的添加/编辑对话框中覆盖提交按钮事件