一个点击下拉框可以选择文本框颜色的案例
这段时间在做一个小项目,过程有一个选择下拉框同时可以将文本框背景设定为指定颜色的需求,经过百度多次寻找,最终在csdn论坛找到一个案例,最终在项目实现想要功能,下面是我的具体实例:
具体代码如下:
网页前台:
< body > < form runat = "server" > <asp:TextBox ID="TextBox1" runat="server" BackColor="#66FFFF" CausesValidation="True" Height="16px" TextMode="MultiLine" Width="420px"></asp:TextBox>
</ form > </ body > |
网页后台:
protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e){ if (DropDownList5.SelectedValue == "红") { TextBox1.Attributes["style"] = "background-color:Red"; // TextBox1.Attributes["style"] = "BackColor:Red"; } else if (DropDownList5.SelectedValue == "黄") { TextBox1.Attributes["style"] = "background-color:Yellow"; } else if (DropDownList5.SelectedValue == "绿") { TextBox1.Attributes["style"] = "background-color:Lime"; } else { TextBox1.Attributes["style"] = "background-color:blue"; } } |