1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script type="text/javascript">
function $(IdElement){
return document.getElementById(IdElement);
}
var TabCheckBox =new Array();
function createInput(x){
Debut = new Date();
for(var i = 0; i < x ;i++)
{
var temp = new InstancieInput(i);
}
Fin = new Date();
alert("CheckBox générées en : " + (Fin-Debut)+ " ms");
}
function InstancieInput(x){
var d = document;
for(var i = 0; i < 100;i++){
var NewInput = d.createElement('input');
NewInput.type = "checkbox";
NewInput.name = x+"_"+i;
//On ajoute l'item en tout premier
document.body.appendChild(NewInput);
}
}
//Cette méthode est géré exprès , j'aurais pus récupérer mes checkbox a leur création<br />
// mais c'est pour me mettre dans le même contexte
function getCheckBox()
{
var ListeInput = document.getElementsByTagName("input");
for(var i = 0 , l = ListeInput.length ; i < l ; i++){
if(ListeInput[i].type=="checkbox")
{
TabCheckBox.push(ListeInput[i]);
}
}
alert("il y a : " + TabCheckBox.length + " CheckBox");
}
function CheckAll()
{
Debut = new Date();
for(var i = 0 , l = TabCheckBox.length ; i < l ; i++)
{
if(TabCheckBox[i].checked)
TabCheckBox[i].checked = false;
else{TabCheckBox[i].checked = true;}
}
Fin = new Date();
alert("CheckBox checkées en : " + (Fin-Debut)+ " ms");
}
function CheckAllByDom()
{
Debut = new Date();
var ListeInput = document.getElementsByTagName("input");
for(var i = 0 , l = ListeInput.length ; i < l ; i++){
if(ListeInput[i].type=="checkbox" && ListeInput[i].checked)
{
ListeInput[i].checked = false;
}
else if(ListeInput[i].type=="checkbox" && !ListeInput[i].checked)
{
ListeInput[i].checked = true;
}
}
Fin = new Date();
alert("CheckBox checkées en : " + (Fin-Debut)+ " ms");
}
//window.onload = createInput(2);
</script>
</head>
<body>
<input type="button" value="Check ALL" id="monBouton" onclick="CheckAll()" />
<input type="button" value="Check ALL by dom" id="monBouton2" onclick="CheckAllByDom()" />
<script type="text/javascript">
createInput(10);
getCheckBox();
</script>
</body>
</html> |