disable all the elements in html

后端 未结 8 1221
清歌不尽
清歌不尽 2020-12-14 09:13

How can we disable all the elements in html through javascript.The easiest way...

相关标签:
8条回答
  • 2020-12-14 09:53

    All the form elements (inputs, selects, textareas) within a form, are accesible through the form.elements HTMLCollection, you can iterate the collection disabling each element:

    function disableForm(form) {
    var length = form.elements.length,
        i;
      for (i=0; i < length; i++) {
        form.elements[i].disabled = true;
      }
    }
    

    Usage examples:

    disableForm(document.forms[0]);
    disableForm(document.getElementById('formId'));
    
    0 讨论(0)
  • 2020-12-14 09:53

    The best way is to add a div with highest z-index having width:100% and height:100%.It will cover your entire page and make everything not clickable means disabled virtually.It is best,because it will not use any loop and any complex code.

    0 讨论(0)
提交回复
热议问题