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
|
<html>
<style type="text/css">
.disabled{
color:grey;
}
</style>
<input type="radio" id="first"/>
<input type="radio" id="second"/>
<input type="radio" id="third"/>
<div id="firstGroup">Premier div</div>
<div id="secondGroup">Second div</div>
<div id="thirdGroup">Troisième div</div>
<script type="text/javascript">
//groupes des noeuds à activer/désactiver
var nodesId=['firstGroup', 'secondGroup', 'thirdGroup'];
var radioButtonsId = ['first', 'second', 'third'];
//ajoute l'attribut disable au node d'id nodeId
//et reactive les autres noeuds
function toogleActivation(nodeId){
for(var i in nodesId){
var node = document.getElementById(nodesId[i]);
node.className='';
}
document.getElementById(nodeId).className='disabled';
}
//reste à chopper l'évènement quand un bouton radio est sélectionné.
function initRadioButtons(radioButtonsId){
for(var i in radioButtonsId){
//pour chacun des radioBoutons, quand on click dessus, on appele toogleActivation
//avec l'id du radioBoutons+'Group'
document.getElementById(radioButtonsId[i]).onclick = function(id){
return function(){
toogleActivation(id+'Group');
};
}(radioButtonsId[i]);
}
};
initRadioButtons(radioButtonsId);
</script>
</html> |
Partager