使用jQuery,如何动态设置选择框的大小属性?

使用jQuery ,如何动态设置选择框的大小属性?

我想在此代码中包含它:

$("#mySelect").bind("click", function() { $("#myOtherSelect").children().remove(); var options = '' ; for (var i = 0; i < myArray[this.value].length; i++) { options += '' + myArray[this.value][i] + ''; } $("#myOtherSelect").html(options).attr [... use myArray[this.value].length here ...]; }); }); 

糟糕,是的

 $('#mySelect').attr('size', value) 
 $("#mySelect").bind("click", function(){ $("#myOtherSelect").children().remove(); var myArray = [ "value1", "value2", "value3" ]; for (var i = 0; i < myArray.length; i++) { $("#myOtherSelect").append( '' ); } $("#myOtherSelect").attr( "size", myArray.length ); });