Script to enable/disable input elements?

前端 未结 5 1640
日久生厌
日久生厌 2020-12-18 18:29

I\'m wondering if it\'s possible for a script to enable/disable all input elements on the page with some sort of toggle button.

I googled it but didn\'t find anythin

5条回答
  •  情歌与酒
    2020-12-18 19:03

    http://code.google.com/p/getelementsbyclassname/

    ^^Robert Nyman has a "get elements by class" script. Basically you'd just assign all those input elements to the same class, and then do something like:

    //Collapse all the nodes
    function collapseNodesByClass(theClass){
      var nodes = getElementsByClassName(theClass);
      for(i = 0; i < nodes.length; i++){
        nodes[i].style.display='none';
      }
    }
    

    This is a piece of code I'm actually currently using to collapse everything with a given class name (it uses the script I mentioned above). But in any case I think the key to your problem is being able to refer to multiple elements at once, which that script will help you with.

    Also the link in your question didn't work for me :(.

提交回复
热议问题