请问,怎样用代码实现文本框里初始的数字为灰色,之后输入的数字为黑色。谢谢

解决方案 »

  1.   


    <asp:TextBox ID="txtPName" CssClass="grayColor"
    onfocus="this.className='blackColor'" Text="defaultText" runat="server"></asp:TextBox>也可以给textbox加focus事件,在里面修改样式
      

  2.   

    在onfecus时更新style和LZ说的有什么区别?
      

  3.   

    我用dreamweaver做的,看不懂asp那个代码啊……
      

  4.   

    一个文本框内的资斧字符只能有一种颜色。
    初始设定为灰色
     然后添加事件 onfocus="this.color='black';"
      

  5.   

    LZ 能否表达清楚点,你的意思是 文本框txta的初始值“111”是灰色而新输入的值“222”是给色,而且结果是“111222”么?
      

  6.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Insert title here</title>
            <style>
                #_input {
                    color: #aaa;
                    border: 1px solid #CC0000;
                    padding: 1px;
                }
            </style>
        </head>
        <body>
            <input type="text" name="textName" value="aa" id="_input">
        </body>

        <script language="javascript">
                var s = document.getElementById("_input");
                s.onfocus = function(){
                    if (this.value == this.defaultValue) 
                        this.value = ''
                };
                s.onblur = function(){
                    if (/^\s*$/.test(this.value)) {
                        this.value = this.defaultValue;
                        this.style.color = '#aaa'
                    }
                }
                s.onkeydown = function(){
                    this.style.color = '#333'
                }
            </script>
    </html>
      

  7.   


    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Demo</title>
    <script type="text/javascript" src="jquery-1.4.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("#txtName").focus(function(){
    $(this).css({color:"Black"});
    });
    });
    </script>
        </head>
        <body>
            <input type="text" value="请输入数字" id="txtName" style="color:Gray'"/>
        </body>
    </html>