快捷通道

JS判断用户名及密码是否为空的方法

欧普莱斯 10
<script type="text/javascript">

  // 验证输入不为空的脚本代码

  function checkForm(form) {

  if(form.username.value == "") {

  alert("用户名不能为空!");

  form.username.focus();

  return false;

  }

  if(form.password.value == "") {

  alert("密码不能为空!");

  form.password.focus();

  return false;

  }

  return true;

  }

</script>

PS一下 调用的话 如果是表单调用 即是

<form action="#" method="post" onsubmit="return checkForm(this);">

</form>