Dans le même genre, 2 checkbox (affiche/masque) individuellement des coins (pull-left/pull-right) sur une collection de boutons et affichent des infos complémentaires...
<input id="check1" type="checkbox" onchange="ShowHide('mag_numero'); ResizeBtn('btn_mag');"><span> Numéros des mags </span> <input id="check2" type="checkbox"" onchange="ShowHide('nombre_articles'); ResizeBtn('btn_mag');"><span> Nombre d'articles </span>
<a id="btn_mag<?php echo $field['numero_mag']; ?>" class="btn btn-success btn-lg ?>" style="width:auto; min-width:250px; height:37px; ..."><span id="numero_mag<?php echo $field['numero_mag']; ?>" class="pull-left" style="display:none; ..."><?php echo $field['numero_mag']; ?></span><span id="articles<?php echo $field['nombre_articles']; ?>" class="pull-right" style="display:none; ..."><?php echo $field['nombre_articles']; ?></span><?php echo $field['mag_theme'] ?></a>
Avec la fonction précédende ShowHide(), j'affiche bien les coins individuellement mais dans la fonction suivante, je recherche à savoir si check1 OU check2 est bien coché pour modifier le width du bouton (<a id="btn_mag....) ; Tout fonctionne parfaitement, jusqu'a ce que je change width:250px; par width:auto; min-width:250px;, la fontion devient alors très instable, le retour "widthValue" semble se confondre avec "max-width" ...
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
| function ResizeBtn(id)
{
collection = document.querySelectorAll("[id^='"+id+"']");
co = collection.length;
for (i = 0; i < co; i++) {
widthValue= parseInt(window.getComputedStyle(collection[i], null).getPropertyValue('width'));
//alert(width);
//collection[i].style.width = (width=='155')?width+26+'px':'';
if (document.getElementById("check1").checked) {
collection[i].style.width = widthValue+26+'px';
}
else {
collection[i].style.width = widthValue-26+'px';
}
if (document.getElementById("check2").checked) {
collection[i].style.width = widthValue+26+'px';
}
else {
collection[i].style.width = widthValue-26+'px';
}
}
//
// for (i = 1; i < 40; i++) {
// var showHide = (document.getElementById(id+i).style.display == 'none' ) ? 'block' : 'none';
// document.getElementById(id+i).style.display = showHide
// }
} |
(ça fonctionne que si j'utilise 2 fonctions individuelles pour chaque checkbox....)
Merci d'avance pour vos idées
Partager