比如我有一堆text,里面是浅灰色的字,如何让我填完每一个,里面的颜色变成红色呢?
 function funClear(){
     var txts=document.getElementsByTagName("input"); 
     for(var i=0;i <txts.length;i++) 
     { 
      if(txts[i].type=="text") 
      { 
       txts[i].onblur("this.style.color='red'")
      } 
     }
    }是这样写吗?能不能动态调用,而不用一个一个的onblur。

解决方案 »

  1.   


    <input type="text" onblur="setColor(this)" /><script type="text/javascript">
        var setColor = function(obj) {
            obj.style.color = "red";
        }    
    </script>
      

  2.   


    <input type="text" value="1111" onblur="setColor(this)" />
    <input type="text" value="2222" onblur="setColor(this)" /><script type="text/javascript">
        var setColor = function(obj) { 
            obj.style.color = "red";
            alert(obj.value);
        }    
    </script>
      

  3.   


    $(":text").onblur(function () {
          $(this).css({'color':'red'});
    })
    试下 应该 没问题了