如何使用asp.net和javascript更改文本框中多个单词的颜色 [英] how to change the color of mutiple words in textbox using asp.net and javascript

查看:64
本文介绍了如何使用asp.net和javascript更改文本框中多个单词的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改文本框中多个单词的颜色.我不想使用富文本框,是否可以更改它.我不需要阅读字符串,颜色只会在文本框中更改.
我尝试了这个,但是颜色没有在文本框中更改,我想在文本框中更改颜色.

how do i change the color of multiple words in textbox. i don''t want to rich text box,is it possible to change it. I need without reading the string,the color changes only in textbox.
i try this,but the color is change not in textbox,i want to change the color in textbox.

window.pageLoad = function () {
                var textbox = document.getElementById('<%= TextBox1.ClientID %>');
                var span = document.getElementById('txt');
                var text = textbox.value;
                var mytool_array = text.split(":");
               alert(text);
                if (mytool_array.length > 0) {
                 span.innerHTML = mytool_array[0] +"<span class="mOver">"  + mytool_array[1] + "</span>";         
                } }
            .mOver
 {
   color:Aqua; 
 }
<asp:TextBox ID="TextBox11" text="Asp:net" onblur="this.style.color='brown'" CssClass="disableCss" runat="server"  TextMode="MultiLine"><span style="color:Olive" id="txt"></span>

推荐答案

可能您需要Richtextbox或任何第三方控件.

顺便说一句,您是否希望文本框可编辑?如果不是(只读),则可以尝试以下肮脏的把戏(DIV是).
Probably you need Richtextbox or any 3rd party control.

BTW do you want the textbox to be editable? If not(Read only) then you can try the following dirty trick(Yes with DIV).
<div style="border: 1px groove #000000; width: 350px;"><span style="color:red;">Red color text</span>  <span style="color:green;">Green color text</span>  <span style="color:blue;">Blue color text</span></div>

输出

OUTPUT

红色文本  绿色文本    蓝色文字
Red color text  Green color text  Blue color text


这篇关于如何使用asp.net和javascript更改文本框中多个单词的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆