js设置input输入框为必选输入框,判断空格或null值

设置input为输入框为必选输入框,即判空:

<form action="demo-form.php">
  Username:<span  style="color:red">*</span> <input type="text" name="usrname" required>
  <input type="submit">
</form>

判断输入值为空格或null值:

if((n.indexOf(" ") >= 0 || n == null)){
	alert("用户名或用户名不能为空格或null值");
	return false;
}