最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

一個(gè)檢測(cè)表單數(shù)據(jù)的JavaScript實(shí)例

 更新時(shí)間:2014年10月31日 16:09:05   投稿:whsnow  
這篇文章主要介紹了一個(gè)檢測(cè)表單數(shù)據(jù)的JavaScript實(shí)例,很簡(jiǎn)單,很實(shí)用,比較適合初學(xué)者

一個(gè)檢測(cè)表單數(shù)據(jù)的JavaScript實(shí)例,很簡(jiǎn)單,很實(shí)用,感興趣的朋友可以看看

  <!DOCTYPE html> 
  <html> 
  <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  <title>每天一個(gè)JavaScript實(shí)例-檢測(cè)表單數(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']");//錯(cuò)誤!??! 
    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> 

相關(guān)文章

  • 超鏈接的禁用屬性Disabled使用示例

    超鏈接的禁用屬性Disabled使用示例

    可以設(shè)置超鏈接的Disabled屬性的true 和 false來(lái)確定超鏈接是不是能點(diǎn)擊,下面有個(gè)示例,大家不妨參考下
    2014-07-07
  • JavaScript中展開(kāi)運(yùn)算符及應(yīng)用的實(shí)例代碼

    JavaScript中展開(kāi)運(yùn)算符及應(yīng)用的實(shí)例代碼

    這篇文章主要介紹了JavaScript中展開(kāi)運(yùn)算符及應(yīng)用的實(shí)例代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • 基于javascript實(shí)現(xiàn)日歷功能原理及代碼實(shí)例

    基于javascript實(shí)現(xiàn)日歷功能原理及代碼實(shí)例

    這篇文章主要介紹了基于javascript實(shí)現(xiàn)日歷效果原理及代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • js實(shí)現(xiàn)視圖和數(shù)據(jù)雙向綁定的方法分析

    js實(shí)現(xiàn)視圖和數(shù)據(jù)雙向綁定的方法分析

    這篇文章主要介紹了js實(shí)現(xiàn)視圖和數(shù)據(jù)雙向綁定的方法,結(jié)合實(shí)例形式分析了vue.js及jQuery數(shù)據(jù)綁定相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2020-02-02
  • JavaScript中的this例題實(shí)戰(zhàn)總結(jié)詳析

    JavaScript中的this例題實(shí)戰(zhàn)總結(jié)詳析

    使用JavaScript開(kāi)發(fā)的時(shí)候,很多人多多少少都會(huì)被this的指向問(wèn)題搞蒙圈,下面這篇文章主要給大家介紹了關(guān)于JavaScript中this例題實(shí)戰(zhàn)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • JavaScript數(shù)組前面插入元素的方法

    JavaScript數(shù)組前面插入元素的方法

    這篇文章主要介紹了JavaScript數(shù)組前面插入元素的方法,涉及javascript中unshift方法的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • NestJS使用class-validator進(jìn)行數(shù)據(jù)驗(yàn)證

    NestJS使用class-validator進(jìn)行數(shù)據(jù)驗(yàn)證

    本文將通過(guò)詳細(xì)的步驟和實(shí)戰(zhàn)技巧,帶大家掌握如何在NestJS中使用class-validator進(jìn)行數(shù)據(jù)驗(yàn)證,以及11條實(shí)戰(zhàn)中常用的驗(yàn)證技巧,感興趣的可以了解下
    2024-11-11
  • JS實(shí)現(xiàn)的四叉樹(shù)算法詳解

    JS實(shí)現(xiàn)的四叉樹(shù)算法詳解

    這篇文章主要介紹了JS實(shí)現(xiàn)的四叉樹(shù)算法,簡(jiǎn)單分析了四叉樹(shù)的相關(guān)概念、原理、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下
    2018-12-12
  • webpack-dev-server搭建本地服務(wù)器的實(shí)現(xiàn)

    webpack-dev-server搭建本地服務(wù)器的實(shí)現(xiàn)

    當(dāng)我們使用webpack打包時(shí),發(fā)現(xiàn)每次更新了一點(diǎn)代碼,都需要重新打包,我們希望本地能搭建一個(gè)服務(wù)器,本文就介紹如何使用webpack-dev-server搭建本地服務(wù)器,感興趣的可以了解一下
    2021-07-07
  • JavaScript實(shí)現(xiàn)將xml轉(zhuǎn)換成html table表格的方法

    JavaScript實(shí)現(xiàn)將xml轉(zhuǎn)換成html table表格的方法

    這篇文章主要介紹了JavaScript實(shí)現(xiàn)將xml轉(zhuǎn)換成html table表格的方法,實(shí)例分析了javascript操作XML文件與table表格的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04

最新評(píng)論

南和县| 林周县| 五河县| 老河口市| 和静县| 扶绥县| 榆林市| 吴堡县| 富民县| 宜川县| 古交市| 商丘市| 罗甸县| 阆中市| 桃园市| 南涧| 通化市| 西安市| 穆棱市| 尖扎县| 岚皋县| 兰溪市| 兴城市| 亳州市| 扎鲁特旗| 新绛县| 革吉县| 汝城县| 商水县| 鄂托克前旗| 江口县| 象山县| 且末县| 景宁| 安顺市| 微博| 石渠县| 朝阳县| 贵溪市| 兴义市| 勐海县|