JSFiddle - React, Tailwind, and code Playground

by boxcore

HTML

<form action="" id="fid" onsubmit="return show()">
  <label for="">账号</label>
  <input type="text" name="username" id="tid">
  <br/>
  <label for="">email</label>
  <input type="text" name="mail" id="mid" />
  <br>
  <label for="">密码</label>
  <input type="password" name="" id="pid">
  <br/>
  <input type="submit" id="sid" value="提交">
  <input type="reset" id="rid" value="重置">
</form>

<script>
function show() {
  var tobj = document.getElementById("tid");
  var pobj = document.getElementById("pid");
  var mail = document.getElementById("mid").value;
  

  
  if (tobj.value && pobj.value) {
    return true;
  } else {
  	alert('请输入账号和密码!');
    return false;
  }
}
</script>

JavaScript

pid.focus();