验证输入框

自己写的提示框 都是判断输入内容 显示提醒框

.pc就是藏起来的 提示框

h5 新特性 有默认弹出框 也有自定义弹出框

<form action="1.php">
  <input type="tel" placeholder="请输入手机号" class="telinput" id="usertel" required pattern="1[3578]d{9}" required="required" minlength="11" />
  <input type="submit" class="apply" id="btnsubmit" value="申请加班" />
  </form>
btnsubmit.onclick = function() {
   
  //自定义错误压过默认的错误消息
  if(usertel.validity.valueMissing) {
  usertel.setCustomValidity('手机号不能为空');
  } else if(usertel.validity.typeMismatch) {
  usertel.setCustomValidity('手机号格式非法');
  } else if(usertel.validity.tooShort) {
  usertel.setCustomValidity('手机号长度必须大于11');
  } else { //没有错误了,清除自定义错误
  usertel.setCustomValidity('');
  //把自定义错误消息设置为空字符串
  }
   
  }
原文地址:https://www.cnblogs.com/peijunma/p/6089637.html