html5表单失去焦点进行非空验证,并用placeholder显示错误提示

html5表单失去焦点进行非空验证,并用placeholder显示错误提示,第1张

简单改了下你的,效果实现了,规范的写法自己改改吧

<!DOCTYPE html>  

<html>  

<head>  

    <meta charset="UTF-8"/>  

    <title>checkValidity 示例</title> 

    <style>

      input.dd::-webkit-input-placeholder{

          color: red

          opacity:1

      } 

       

    </style>

</head>  

<body> 

<form action="" method="get">

<table width="200%" border="0" cellspacing="0" cellpadding="0" >

  <tr>

    <td><input class='' id='id' name="uname" type="text" placeholder="ID" onblur="aa(this)"></td>

  </tr>

  <tr>

    <td><input name="pwd" type="password" placeholder="密码"></td>

  </tr>

  <tr>

    <td><input name="" type="submit"></td>

  </tr>

</table>

</form>

<script> 

  function aa(a){

      if(a.value==''){

        a.placeholder='ID不能为空'

       a.className="dd"

      }

  }

</script>

</body>  

</html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html charset=gb2312" />

<title>文哥讨厌IE</title>

<script language="javascript" type="text/javascript">

function checkMobile(str) {

    if(str==""){

        alert("手机号不能为空!")

    }

    else{

        var re = /^1\d{10}$/

        if (re.test(str)) {

            alert("正确")

        } else {

            alert("手机号格式错误!")

        }

    }

}

</script>

</head>

<body>

<input type="text" id="btn_getNum"/>

<input type="button" value="得到数字" onclick="checkMobile(btn_getNum.value)"/>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/6297343.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-20
下一篇 2023-03-20

发表评论

登录后才能评论

评论列表(0条)

保存