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

<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);">
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容