2008-09-15 62 views
11

使用jQuery,如何動態設置選擇框的大小屬性?使用jQuery,我該如何動態設置選擇框的大小屬性?

我想包括它在這個代碼:

$("#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 ...]; 
    }); 
}); 

回答

23

糟糕,

$('#mySelect').attr('size', value) 
1
$("#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); 
}); 
相關問題