2008-09-15 16 views
11

Sử dụng jQuery, làm cách nào tôi có thể tự động đặt thuộc tính kích thước của một hộp chọn?Sử dụng jQuery, làm cách nào tôi có thể tự động đặt thuộc tính kích thước của một hộp chọn?

Tôi muốn đưa nó vào trong mã này:

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

Trả lời

23

Rất tiếc, đó là

$('#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); 
}); 
Các vấn đề liên quan