“Agregar atributo requerido JavaScript” Código de respuesta

JavaScript Agregar atributo requerido a la entrada

element.setAttribute("required", "");    //turns required on
element.required = true;                 //turns required on through reflected attribute
jQuery(element).attr('required', '');    //turns required on
$("#elementId").attr('required', '');    //turns required on

element.removeAttribute("required");     //turns required off
element.required = false;                //turns required off through reflected attribute
jQuery(element).removeAttr('required');  //turns required off
$("#elementId").removeAttr('required');  //turns required off

if (edName.hasAttribute("required")) { }  //check if required
if (edName.required) { }                 //check if required using reflected attribute
Prasanth PPS

JavaScript Agregar requerido a la entrada

element.setAttribute("required", "");

element.removeAttribute("required");
Fancy Fowl

Agregar atributo requerido JavaScript

// if you want the element to be required at submission of form
element.required = true;
Perfect Porcupine

Agregar atributo requerido JavaScript


element.setAttribute("required", "");    //turns required on
element.required = true;                 //turns required on through reflected attribute
jQuery(element).attr('required', '');    //turns required on
$("#elementId").attr('required', '');    //turns required on

element.removeAttribute("required");     //turns required off
element.required = false;                //turns required off through reflected attribute
jQuery(element).removeAttr('required');  //turns required off
$("#elementId").removeAttr('required');  //turns required off

if (edName.hasAttribute("required")) { }  //check if required
if (edName.required) { }                 //check if required using reflected attribute

Different Dormouse

Respuestas similares a “Agregar atributo requerido JavaScript”

Preguntas similares a “Agregar atributo requerido JavaScript”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código