function captlz(obj){
   var str = obj.value;
   if (str!==""){
       str = str.replace(/\b(\w+)\b/g, function($1){
       return $1.substring(0,1).toUpperCase() + $1.substring(1);
       });
   }
   alert(str);
}

解决方案 »

  1.   

    楼上大哥,加入输入框中无效阿<input type="text" name="yourname" id="yourname" onBlur="captlz(this)" onkeyup="captlz(this)">
      

  2.   


    <script>
    function captlz(obj){
       var str = obj.value;
       if (str!==""){
           str = str.replace(/\b(\w+)\b/g, function($1){
           return $1.substring(0,1).toUpperCase() + $1.substring(1);
           });
       }
       obj.value = str;
    }</script>
    <input type="text" name="yourname" id="yourname" onBlur="captlz(this)" onkeyup="captlz(this)">