如何更改文本框的前景色和背景色?颜色是由用户选择的? [英] how to change a forecolor and backcolor of textbox? color are selected by the user?
本文介绍了如何更改文本框的前景色和背景色?颜色是由用户选择的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i我正在开发一个网页,其中包含一个用户选项,他们为他们提供的文字改变了前色和背景色?,现在我正在使用颜色选择器来选择一种颜色,然后我如何将所选颜色分配给他们在网页上输入的文字。
以下颜色挑选代码:
< asp:TextBox ID =txt_forerunat =serverontextchanged =txt_fore_TextChanged>< / asp:TextBox>
< asp:ColorPickerExtender ID =ColorPickerExtender1runat =serverTargetControlID =txt_foreOnClientColorSelectionChanged =colorChangedSampleControlID =txt_sfore>
< / asp:ColorPickerExtender>
现在我正在努力改变用户信息的文本框,并以同样的方式更改文本框的bgcolor?
如何?
解决方案
在colorChanged javascript方法中你可以使用
文件.getElementById(''txt'')。style.background =''#FF0000''; //将颜色代码放在这里
document.getElementById(''txt'')。style.color =''#00FF00''; //将颜色代码放在这里
或者如果你使用的是jquery
例如
(''#txt'')。attr(''style'',''color:red; background:green;'');
txt_usertxt.ForeColor = System.Drawing.ColorTranslator.FromHtml( # + txt_fore.Text);
txt_usertxt.BackColor = System.Drawing.ColorTranslator.FromHtml( # + txt_back。文本);
hi everyone,
i am developing a web page that contain a option for user, who change fore color and background color for the text they are providing ?, now i am using a color picker to choose a color, then how i assign selected color to text of they typing in the webpage.
below code for color picking:
<asp:TextBox ID="txt_fore" runat="server" ontextchanged="txt_fore_TextChanged"></asp:TextBox> <asp:ColorPickerExtender ID="ColorPickerExtender1" runat="server" TargetControlID="txt_fore" OnClientColorSelectionChanged="colorChanged" SampleControlID="txt_sfore"> </asp:ColorPickerExtender>
now i am struggle for change forecolor the textbox of user information, and also change bgcolor of textbox in the same way?
how?
解决方案
In the colorChanged javascript method you can use
document.getElementById(''txt'').style.background = ''#FF0000''; // put color code in here document.getElementById(''txt'').style.color = ''#00FF00''; // put color code in here
or if you are using jquery
e.g.
(''#txt'').attr(''style'', ''color:red;background:green;'');
txt_usertxt.ForeColor = System.Drawing.ColorTranslator.FromHtml("#" + txt_fore.Text); txt_usertxt.BackColor = System.Drawing.ColorTranslator.FromHtml("#" + txt_back.Text);
这篇关于如何更改文本框的前景色和背景色?颜色是由用户选择的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文