a.value.length>0
表示输入了东西

解决方案 »

  1.   

    要准确地判断还要考虑用户敲入空格的情况!
    <input type=text name=a>
    <script language=javascript>
    String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}if(document.all.a.value.Trim()=="")alert("为空");
    else alert("不为空");
    </script>
      

  2.   

    <input type=text name=a value="  a ">
    <input type=button value=check onclick=check(a.value)>
    <script language=javascript>
    function check(str){
    if(/^\s*$/.test(str))alert("为空");
    else alert("不为空");
    }
    </script>
      

  3.   

    <form name=form1 onsubmit="return check();">
    <input type=text name=password>
    <input type=submit name="登录">
    </form>
    <script language="javascript">
    function check()
    {
      if(document.form1.password.value=="")
      {
        alert("密码不能为空!");
        form1.password.focus();
        return false;
      }
    }
    </script>