使用单选按钮更改文本框的背景颜色

编程入门 行业动态 更新时间:2024-10-24 19:14:37
本文介绍了使用单选按钮更改文本框的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Hai Friend's, 我的项目有一个小问题... 在我的Web表单中,我在单选按钮旁边有5个单选按钮,我有5个文本框,当我单击特定的单选按钮时,我想突出显示文本框的背景颜色

Hai Friend''s, I have a small problem with my project ... In my web form i have 5 radio buttons beside radio buttons i have 5 text boxes and i want to highlight the text box background color when i click on the particular radio button

推荐答案

将此样式标签放置在头部 place this style tag in head part <style type="text/css"> .mystyle { color: Blue; background-color: Red; border: 2px solid #DCDCDC; } .nocolor { background-color: White; } </style>

将此脚本放在头部

place this script in head part

<script type="text/javascript"> var previousbox = 'TextBox1'; function changecolor(rid) { document.getElementById(rid).className = "mystyle"; document.getElementById(previousbox).className = "nocolor"; previousbox = rid; } </script>

您的设计代码应该是这样的

and your design code should like this

<table width="50%"> <tr> <td> <input type="radio" id="Radio1" onclick="changecolor('TextBox1')" name="a" /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <input type="radio" id="Radio2" onclick="changecolor('TextBox2')" name="a" /><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <input type="radio" id="Radio3" onclick="changecolor('TextBox3')" name="a" /><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <input type="radio" id="Radio4" onclick="changecolor('TextBox4')" name="a" /><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <input type="radio" id="Radio5" onclick="changecolor('TextBox5')" name="a" /><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> </td> </tr> </table>

亲爱的朋友, 这是成功的答案........ 设计页面 =========== Dear Friends, This is Successful answer .......... Design Page =========== <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"> <asp:ListItem Value="Red">Red <asp:ListItem Value="green">Green <asp:TextBox ID="TextBox1" runat="server">

背后的代码 =========== 只需也包括此名称空间......

Code behind ============ Just Include this Name space also.........

using System.Drawing; protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if (RadioButtonList1.SelectedValue == "Red") { TextBox1.BackColor = Color.Red; } else { TextBox1.BackColor = Color.Green; } }

试试这个可爱的答案.........这是对您的帮助.

Try this Cute answer.........which is helpfil to u.

试试这个 Hi, try this <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"> <asp:ListItem Value="Red">Red</asp:ListItem> <asp:ListItem Value="green">Green</asp:ListItem> </asp:RadioButtonList> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

背后的代码

Code Behind

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if (RadioButtonList1.SelectedValue == "Red") { TextBox1.BackColor = Color.Red; } else { TextBox1.BackColor = Color.Green; } }

祝你好运

Best Luck

更多推荐

使用单选按钮更改文本框的背景颜色

本文发布于:2023-06-09 04:12:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/594994.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   单选   按钮   颜色   背景

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!