function lcase(){if (this.value != this.value.toUpperCase()) this.value=this.value.toUpperCase();}<input type="text" onkeyup="lcase();"/>IE下显示this.value为空,FF下显示,“this.value is undefined" 请问该怎么改?

解决方案 »

  1.   


    <body>
    <script language="javascript">
    <!--
    function lcase(_this){if (_this.value != _this.value.toUpperCase()) _this.value=_this.value.toUpperCase();}
    //-->
    </script>
    <input type="text" onkeyup="lcase(this);"/></body>
      

  2.   

    function lcase(txt){if (txt.value != txt.value.toUpperCase()) txt.value=txt.value.toUpperCase();}
    <input type="text" onkeyup="lcase(this);"/>
      

  3.   

    也可以这么写.你那个this是指向函数运行时实体哦.要这么写才是指向控件.
    <body>
    <script language="javascript">
    <!--
    function lcase(){if (this.value != this.value.toUpperCase()) this.value=this.value.toUpperCase();}//-->
    </script>
    <input type="text" onkeyup="lcase.apply(this);"/></body>