input 文字颜色

<!doctype html>
<html>
    <head>
        <meta charset="gb2312" />
        <style>
             
        </style>
    </head>
    <body>
        <input id="test" type="text" value="默认" style="color:#999;" />
        <script>
            function $(o){return document.getElementById(o)}
            $('test').onfocus = function(){
                if( this.value == this.defaultValue ){
                    this.value = '';
                    this.style.color = '#000';
                }
            }
            $('test').onblur = function(){
                if( this.value == '' || this.value == this.defaultValue ){
                    this.value = this.defaultValue;
                    this.style.color = '#999';
                }
            }           
        </script>
    </body>
</html>

 

posted @ 2017-01-19 13:39  ghfjj  阅读(254)  评论(0编辑  收藏  举报