解决方案 »

  1.   

    三个问题
    1. 你使用了document.getElementById,但是你的input里面都没有id属性,只有name属性;
    2. 就算你设置了id,document.getElementById("")取出的是元素,不是元素的value;
    3. document.getElementById("userid")=="admin"||document.getElementById("password")=="admin"这个表示用户名和密码只要其中有一个的值是admin就表示登录成功,普遍的做法是用户名和密码都需要匹配才算登录成功。
    修改了你的代码,可以点击查看在线演示代码,下面是源码function demon(){
        var userid = $("userid").value;
        var password = $("password").value;
        if( userid == "" || password == "")
        {
            alert("用户名或密码不能为空");
        }
        else if(userid == "admin" && password == "admin"){
            alert("登陆成功!");
        }
        else{
            alert("账号有误,请重新输入!");
        }
    }
    function $(id){
        return document.getElementById(id);
    }
    <form action=""method="post">
        帐号:<input type="text" name="userid" id="userid" /><br />
        密码:<input type="text" name="password" id="password" /><br />
        <input type="button"value="登陆"onclick="demon()" />
        <input type="reset"value="重置" />
    </form>
      

  2.   

    你getElementById(""),但你的input标签里没有,所以找不到,
    form action=""method="post">
        帐号:<input type="text" name="userid" id="userid" /><br />
        密码:<input type="text" name="password" id="password" /><br />
        <input type="button"value="登陆"onclick="demon()" />
        <input type="reset"value="重置" />
    </form>
      

  3.   

    把input都添加上id,根据name是娶不到的