“Tambahkan atribut yang diperlukan JavaScript” Kode Jawaban

JavaScript menambahkan atribut yang diperlukan ke input

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 Tambahkan Diperlukan untuk Input

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

element.removeAttribute("required");
Fancy Fowl

Tambahkan atribut yang diperlukan JavaScript

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

Tambahkan atribut yang diperlukan 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

Jawaban yang mirip dengan “Tambahkan atribut yang diperlukan JavaScript”

Pertanyaan yang mirip dengan “Tambahkan atribut yang diperlukan JavaScript”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya