Loop nos objetos HTML com prototype

<html>
<header>
 <script src="prototype.js"></script>
</header>
<body>
 <input type="checkbox" id="che1" name="che" /> 1 <br />
 <input type="checkbox" id="che2" name="che" /> 2 <br />
 <input type="checkbox" id="che3" name="che" /> 3 <br />
 <input type="checkbox" id="che4" name="che" /> 4 <br />
 <input type="checkbox" id="che5" name="che" /> 5 <br />
 <input type="button" value="Marcar" onclick="fnMarcar(true);" /> <br />
 <input type="button" value="Desmarcar" onclick="fnMarcar(false);" /> <br />
 <script type="text/javascript">
 function fnMarcar(tipo){
 $$('input').each(function(e){
 if(e.type == 'checkbox' && e.name == 'che'){
 e.checked = tipo;
 }
 });
 }
 </script>

</body>
</html>

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

This site uses Akismet to reduce spam. Learn how your comment data is processed.