Using jQuery, how can I dynamically set the size attribute of a select box?

前端 未结 2 1582
不思量自难忘°
不思量自难忘° 2021-01-11 15:09

Using jQuery, how can I dynamically set the size attribute of a select box?

I would like to include it in this code:

$(\"#mySelect\").bind(\"click\",         


        
相关标签:
2条回答
  • 2021-01-11 15:47
    $("#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 );
    });
    
    0 讨论(0)
  • 2021-01-11 15:52

    Oops, it's

    $('#mySelect').attr('size', value)
    
    0 讨论(0)
提交回复
热议问题