<!DOCTYPE html><html>? <head>? ? <meta charset="utf-8">? ? <title></title>? ? <style media="screen">? ? ? #email{? ? ? ? width: 250px;? ? ? ? background-color: rgb(173, 182, 191);? ? ? }? ? </style>? </head>? <body>? ? <div class="">? ? ? 請輸入郵箱:<input id="email" type="text" name="" value="" placeholder="請輸入郵箱:例如123231@qq.com" required>*<br>? ? </div>? ? <script type="text/javascript">? ? ? //封裝獲得id? ? ? function $id(id){? ? ? ? ?return document.getElementById(id);? ? ? }? ? ? //獲得郵箱? ? ? $id("email").onblur=function () {? ? ? ? var regExp=/^[0-9a-zA-Z_]+[@][0-9a-zA-Z_]+(.[a-zA-Z]{1,2})$/;? ? ? ? if (regExp.test(this.vale)) {? ? ? ? ? // this.setAttribute('backgroung-color','greed');? ? ? ? ? // this.style.backgroundColor = "green";? ? ? ? ? this.style.cssText='background-color:green;width:10px;'? ? ? ? }? ? ? ? else {? ? ? ? ? // this.setAttribute('backgroung-color','red');? ? ? ? ? ? // this.style.backgroundColor = "red";? ? ? ? ? ? this.style.cssText='background-color:red;width:10px;'? ? ? ? }? ? ? }? ? </script>? </body></html>
為什么第一二中方法顏色沒有 .css是jq的方法吧
慕九州8427191
2018-11-03 10:53:19