Avec jQuery, comment puis-je définir dynamiquement l'attribut de taille d'une zone de sélection?
-
09-06-2019 - |
Question
À l'aide de jQuery , comment puis-je définir de manière dynamique l'attribut de taille d'une zone de sélection?
J'aimerais l'inclure dans ce code:
$("#mySelect").bind("click",
function() {
$("#myOtherSelect").children().remove();
var options = '' ;
for (var i = 0; i < myArray[this.value].length; i++) {
options += '<option value="' + myArray[this.value][i] + '">' + myArray[this.value][i] + '</option>';
}
$("#myOtherSelect").html(options).attr [... use myArray[this.value].length here ...];
});
});
La solution
Oups, c'est
$('#mySelect').attr('size', value)
Autres conseils
$("#mySelect").bind("click", function(){
$("#myOtherSelect").children().remove();
var myArray = [ "value1", "value2", "value3" ];
for (var i = 0; i < myArray.length; i++) {
$("#myOtherSelect").append( '<option value="' + myArray[i] + '">' + myArray[i] + '</option>' );
}
$("#myOtherSelect").attr( "size", myArray.length );
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow