Una instancia de JavaScript que detecta datos de formulario es muy simple y práctica. Los amigos interesados pueden echar un vistazo
<! DOCTYPE HTML> <html> <EvIn> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> una instancia de JavaScript por día-detectar datos de formulario </title> <syle> [role = "alerta"] {background-color: #fcc; Font-Weight: Bold; relleno: 5px; borde: 1px discontinuo #000; } div {margen: 10px 0; relleno: 5px; Ancho: 400px; Color de fondo: #fff; } </style> <script> window.onload = function () {document.getElementById ("Thirdfield"). OnChange = ValidateField; document.getElementById ("FirstField"). Onblur = obligatoryField; document.getElementById ("testForm"). onsubmit = finalCheck; } function validateField () {removealert (); if (! isnan (parsefloat (this.value))) {resetfield (this); } else {badfield (this); GenerateAlert ("usted ingresó un valor no válido en el tercer campo. Solo se permiten valores numéricos como 105 o 3.45"); }} función removealert () {var msg = document.getElementById ("msg"); if (msg) {document.body.removechild (msg); }} función resetfield (elem) {elem.parentnode.setattribute ("style", "background-color: #fff"); var válido = elem.getAttribute ("aria-inválido"); if (válido) elem.removeattribute ("aria-inválido"); } function badfield (elem) {elem.parentnode.setattribute ("estilo", "fondos de color#tarifa"); Elem.SetAttribute ("aria-inválido", "verdadero"); } function GenerateAlert (txt) {var txtnd = document.createTextNode (txt); msg = document.createElement ("div"); msg.SetAttribute ("rol", "alerta"); msg.setAttribute ("id", "msg"); msg.SetAttribute ("clase", "alerta"); msg.appendChild (txtnd); document.body.appendChild (msg); } function obligatoryField () {removealert (); if (this.value.length> 0) {resetfield (this); } else {badfield (this); GenerateAlert ("Debe ingresar un valor en el primer campo"); }} función finalCheck () {//console.log("aaa "); removealert (); VAR Fields = document.QuerySelectorAll ('input [aria-invalid = "true"]'); // var Fields = document.QuerySelectorAll ("Entrada [aria-Invalid = 'True']"); // Error! ! ! console.log (campos); if (Fields.length> 0) {GenerateAlt ("tiene entradas de campos incorrectos que deben solucionarse antes de poder enviar este formulario"); devolver falso; }} </script> </head> <body> <form de formulario = "testform"> <div> <label for = "firstfield">*primer campo: </label> <br/> <input id = "Firstfield" name = "firstfield" type = "text" aria-required = "true"/> </div> <div> <lelebelebrel para = "segundo" "Secondfield" type = "text" /> </div> <iv> <etiqueta for = "tercero"> tercer campo (numérico): </label> <br /> <input id = "tercero" name = "tercero" type = "text" /> </div> <div> <label for = "Cuarthfield"> Cuarto campo: < /etiqueta> <Br /> <input id = "Fourthfield" name = "Fourthfield" </div> <input type = "subt" value = "Enviar datos"/> </form> </body> </html>