Using javascript to disable all text boxes drop down menus multi line text fields on the web page

  • 2020-03-30 00:56:18
  • OfStack

The idea is to loop through the control on the page and set the disabled property to true.

The code is as follows:


<script type="text/javascript">
    var nodeList = document.getElementsByTagName("input");
    for (var i = 0; i < nodeList.length; i++) {
        nodeList[i].disabled = true;
    }
    nodeList = document.getElementsByTagName("select");
    for (var i = 0; i < nodeList.length; i++) {
        nodeList[i].disabled = true;
    }
    nodeList = document.getElementsByTagName("textarea");
    for (var i = 0; i < nodeList.length; i++) {
        nodeList[i].disabled = true;
    }
</script>

Here are the types of these controls:

Through the document. The getElementsByName (" controlName ") [0]. The toLocaleLowerCase () can get.

Depending on the control, there are several types:
"Text"
"The textarea"
"Select - one"
"Select - multiple"
"Radio"
"Checkbox"


Related articles: