-1

这对我没有任何意义。

我正在尝试使用 jquery .css() 根据窗口高度设置某些按钮的“最小高度”。

不管出于什么原因,它只是设置了第一个按钮匹配的最小高度,但是有 16 个匹配按钮。

http://jsfiddle.net/VDtgT/20/embedded/result/

“#tab-btn-2”是问题所在。这是我正在使用的 javascript:

<script>
$( document ).ready( function(){
  setMaxHeight();
  $( window ).bind( "resize", setMaxHeight ); 

  function setMaxHeight() {
    $( "#tab-content-1" ).css( "max-height", ( $( window ).height() * 0.67 | 0 ) + "px" );
    $( "#tab-content-1" ).css( "min-height", ( $( window ).height() * 0.67 | 0 ) + "px" );
    $( "#tab-content-2" ).css( "max-height", ( $( window ).height() * 0.67 | 0 ) + "px" );
    $( "#tab-content-2" ).css( "min-height", ( $( window ).height() * 0.67 | 0 ) + "px" );
    $( "#tab-content-3" ).css( "max-height", ( $( window ).height() * 0.67 | 0 ) + "px" );
    $( "#tab-content-3" ).css( "min-height", ( $( window ).height() * 0.67 | 0 ) + "px" ); 
    $( "#tab-btn-2" ).css( "min-height", ( $( window ).height() * 0.67 | 0 ) + "px" );

  }

});
</script>
4

2 回答 2

3

ID 是唯一的,jQuery 只会找到具有特定 ID 的第一个元素,因为应该只有一个。

您需要改用一个类。

$( ".tab-btn-2" ).css( ....
于 2013-04-02T17:35:46.187 回答
0

一种选择是为每个按钮提供相同的类名并使用该类来设置最小高度(相对于 id)。对于页面上的每个元素,您的 id 应该是唯一的。

<input type=button id=whatever class="tab-btn-2" />
...
$( ".tab-btn-2" ).css( "min-height", ( $( window ).height() * 0.67 | 0 ) + "px" );
于 2013-04-02T17:36:19.760 回答