【问题标题】:Using jQuery, how can I dynamically set the size attribute of a select box?使用jQuery,如何动态设置选择框的大小属性?
【发布时间】:2010-09-09 01:49:18
【问题描述】:

使用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 ...];
    });
});

【问题讨论】:

    标签: jquery


    【解决方案1】:

    糟糕,是

    $('#mySelect').attr('size', value)
    

    【讨论】:

      【解决方案2】:
      $("#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 );
      });
      

      【讨论】:

        猜你喜欢
        • 2013-09-22
        • 1970-01-01
        • 2011-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多