El uso de jQuery, ¿cómo puedo establecer dinámicamente el tamaño de atributo de un cuadro de selección?
-
09-06-2019 - |
Pregunta
El uso de jQuery, cómo puedo establecer dinámicamente el tamaño de atributo de un cuadro de selección?
Me gustaría incluir en este código:
$("#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 ...];
});
});
Solución
Uy, es
$('#mySelect').attr('size', value)
Otros consejos
$("#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 );
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow