....javascript忘记的一干二净了<script type="text/javascript">
function CheckName()

if (document.form.textfield.value.length == 0) { 
alert("请输入您姓名!");
document.form.textfield.focus();
return false;
}
return true;
}
function CheckPass()

if (document.form.textfield2.value.length == 0) { 
alert("请输入您密码!");
document.form.textfield2.focus();
return false;
}
return true;
}
</script>上面写了2个验证
现在想用把他们写到1个function里面 用onclick调用 
不记得怎么写了 拿分的速度来

解决方案 »

  1.   

    function CheckName()

    if (document.form.textfield.value.length == 0) { 
    alert("请输入您姓名!");
    document.form.textfield.focus();
    return false;
    }
    if (document.form.textfield2.value.length == 0) { 
    alert("请输入您密码!");
    document.form.textfield2.focus();
    return false;
    }
    return true;
    }
      

  2.   

    你想要什么方法。document.form.onsubmit = function() {
    if (document.form.textfield.value.length == 0) { 
    alert("请输入您姓名!");
    document.form.textfield.focus();
    return false;
    }
    if (document.form.textfield2.value.length == 0) { 
    alert("请输入您密码!");
    document.form.textfield2.focus();
    return false;
    }
    return true;
    };
      

  3.   

    如果想转到别的页,直接写window.location.href='url';url代表你的地址。
      

  4.   

    我说的是这个方法 邓肯哥function check(){
                    if (checkname() && checkpass() ) {
                        return true;
                    }
                    else {
                        return false;
                    }
      

  5.   

    如果你要在js中转就这样写就可以了,不用他return true了,直接window.location.href即可,如果是在form中,直接在里面写上地址,这里返回true的话,他就转走了!!!!刚才没有写完,算是补充一下吧!
      

  6.   

    我在纯html里写的javascript 表单验证
    其他的都用不上 想在html里面判断 如果2个都不为空那么跳到另外个页面
    现在不为都实现了 就想跳转
      

  7.   


    function CheckForm() {
      var form = document.form;
      if (form.textfield.value.length == 0) {
         //这里最好不要用alert,你可以考虑在输入框后面加行红字提示
         form.textfield.focus();
         return false;
      } else if (form.textfield1.value.length == 0) {
         form.textfield1.focus();
         return false
      } else {
        return true;
      }
    }
    <form action="a.html" onsubmit="CheckForm()"></form>
      

  8.   

    这样的也可以function check(){
                    if (checkname() && checkpass() ) {
                        return true;
                    }
                    else {
                        return false;
                    }