/** * @param {String}eleId * @param {Object}reg */ function checkInput(eleId,reg) { var ele = document.getElementById(eleId); ele.onblur = function (ev) { if(!reg.test(this.value)){ //不匹配 this.style.borderColor = "#ff0000" //紅色 }else{ //匹配 this.style.borderColor = "#cccccc" //白色 } } } //驗證手機號 checkInput("phone",/^13[0-9]\d{8]$/)
<div id = "testDiv">測試一個div</div> <script> var str = "jdi"; console.log(window.str); console.log(document); console.log(document === window.document); console.log(document.childNodes); console.log(document.head); console.log(document.body); console.log(document.title); var box = document.getElementById("testDiv"); console.log(box); console.log(box.innerText); </script>
運行結果:
javascript
https://github.com/ruigege66/JavaScript/blob/master/D26_1_FormVerification.html
https://www.cnblogs.com/ruigege0000/
https://blog.csdn.net/weixin_44630050?t=1