日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 互聯(lián)網(wǎng) > 每天一個(gè)JavaScript實(shí)例-檢測表單數(shù)據(jù)

每天一個(gè)JavaScript實(shí)例-檢測表單數(shù)據(jù)

來源:程序員人生   發(fā)布時(shí)間:2014-11-30 09:35:40 閱讀次數(shù):3476次
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF⑻" /> <title>每天1個(gè)JavaScript實(shí)例-檢測表單數(shù)據(jù)</title> <style> [role="alert"]{ background-color: #fcc; font-weight: bold; padding:5px; border:1px dashed #000; } div{ margin:10px 0; padding:5px; width:400px; background-color: #fff; } </style> <script> window.onload = function(){ document.getElementById("thirdfield").onchange = validateField; document.getElementById("firstfield").onblur = mandatoryField; document.getElementById("testform").onsubmit = finalCheck; } function validateField(){ removeAlert(); if(!isNaN(parseFloat(this.value))){ resetField(this); }else{ badField(this); generateAlert("You entered an invalid value in Third Field. only numeric values such as 105 or 3.45 are allowed"); } } function removeAlert(){ var msg = document.getElementById("msg"); if(msg){ document.body.removeChild(msg); } } function resetField(elem){ elem.parentNode.setAttribute("style","background-color:#fff"); var valid = elem.getAttribute("aria-invalid"); if(valid) elem.removeAttribute("aria-invalid"); } function badField(elem){ elem.parentNode.setAttribute("style","background-color#fee"); elem.setAttribute("aria-invalid","true"); } function generateAlert(txt){ var txtNd = document.createTextNode(txt); msg = document.createElement("div"); msg.setAttribute("role","alert"); msg.setAttribute("id","msg"); msg.setAttribute("class","alert"); msg.appendChild(txtNd); document.body.appendChild(msg); } function mandatoryField(){ removeAlert(); if(this.value.length > 0 ){ resetField(this); }else{ badField(this); generateAlert("You must enter a value into First Field"); } } function finalCheck(){ //console.log("aaa"); removeAlert(); var fields =document.querySelectorAll('input[aria-invalid="true"]'); //var fields =document.querySelectorAll("input[aria-invalid='true']");//毛病!!! console.log(fields); if(fields.length > 0){ generateAlert("You have incorrect fields entries that must be fixed before you can submit this form"); return false; } } </script> </head> <body> <form id = "testform"> <div> <label for="firstfield">*first Field:</label><br /> <input id="firstfield" name = "firstfield" type = "text" aria-required = "true" /> </div> <div> <label for="secondfield">Second Field:</label><br /> <input id="secondfield" name = "secondfield" type = "text" /> </div> <div> <label for="thirdfield">Third Field(numeric):</label><br /> <input id="thirdfield" name = "thirdfield" type = "text" /> </div> <div> <label for="fourthfield">Fourth Field:</label><br /> <input id="fourthfield" name = "fourthfield" type = "text" /> </div> <input type="submit" value = "Send Data" /> </form> </body> </html>

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 综合精品久久 | 久久久久免费网站 | 久久久久综合 | 中文字幕在线观看一区二区三区 | 成人免费激情视频 | 亚洲综合免费 | 国产成人精品一区二区三区在线 | 91偷拍视频 | 亚洲精品电影网在线观看 | 成人亚洲免费视频 | 国产精品乱码久久久久久 | 久久自己只精产国品 | 亚洲 欧美 综合 | 亚洲国产精品久久 | 国产精品久久久久久久免费大片 | 蜜桃av鲁一鲁一鲁一鲁 | 天堂av在线免费观看 | 女人18毛片九区毛片在线 | a中文在线视频 | 久久性 | 亚洲一区精品视频 | 麻豆一区二区 | 成人福利在线观看 | 久久久久久综合 | 婷婷精品国产一区二区三区日韩 | 日韩不卡 | julia中文字幕久久一区二区 | 久久视频免费观看 | 99久久精品国产毛片 | 中文字幕+乱码+中文乱码图片 | 欧美一区二区三区在线看 | 久久久夜精品 | 天天艹在线观看 | 一级特黄在线观看 | 91精品国产综合久久福利 | 亚洲精品黄色 | 日本亚洲精品 | 亚洲1区 | 三级欧美 | 91视频免费看 | 热久久久 |