2009-11-11 6 views
-1

여기 새로 왔습니다. 나는 데이터베이스에서 데이터를 보여줄 수있는 테이블을 만들고, 선택 될 데이터를 보여줄 1 개의 테이블을 더 만든다. 그러나 문제는 우리가 단지 몇 가지 데이터를 선택하면 문제가되지 않을 것이라는 것입니다. 그러나 100 개 이상의 데이터를 선택하면 레이아웃 문제가 발생할 수 있습니다. 스크롤바 만드는 법?

이 내 코드

...

<script type="text/javascript"> 
function List(){ 
    var selectedProduct = ""; 
    var product = document.getElementById('product'); 
    var output ="";   
    var k = 0; 
    var name = new Array; 
    var model = new Array; 
    var unitprice = new Array; 

     <?php foreach ($productPrices as $price): ?> 
      name[k] = "<?php echo $price['Product']['txtname']; ?>"; 
      model[k] = "<?php echo $price['Product']['txtmodel']; ?>"; 

      k++; 
     <?php endforeach; ?> 

     k=0; 
     for (var i = 0; i < product.length; i++) { 
       k = product.options[i].value; 

      if (product.options[i].selected) { 
       output += '<tr>'+ 
           '<td style="border-right: 0px; width:270px; text-align:center" id="ProductProduct'+k+'" name="data[Product][Product]['+k+']">'+name[i]+'</td>'+ 
           '<td style="border-right: 0px; width:100px; text-align:left" id="ProductProduct'+k+'" name="data[Product][Product]['+k+']">'+model[i]+'</td>'+ 
          '</tr>';  
      } 
     } 
     output = '<table style="width:500px; border: 0px;">'+output+'</table>';   
     document.getElementById('productTable').innerHTML = output; 
}     
</script> 

<table cellpadding="0" cellspacing="0" style="width:100%"> 
    <caption><div align="left">Peoduct Selection</div></caption> 
    <tr> 
     <th style="width:25%"><font><div align="left">Select Product :</div></font> 
        <?php echo $form->input('Product',array(
          'label' => 'Select Products', 
          'options' => $products, 
          'id'=>'product', 
          'style'=>'width:250px;height:100px', 
          'selected' => $html->value('Product.Product'), 
          'onchange'=>'List();')); ?> </th> 
     <th ><table> 
      <tr> 
       <th style="width:400px"><div align="center">Product Name</div></th> 
       <th style="width:250px"><div align="center">Product Model</div></th> 
      </tr> 
      <tr> 
       <td colspan="4" ><span id="productTable"></td> 
      </tr> 
     </table></th> 
    </tr> 
    </table> 

사람은 내가이 문제를 해결 도와 드릴까요? thx ..

+0

왜 내 리 태그를 변경 했습니까? 이 질문은 PHP와는 아무 관련이 없으며 레이아웃 때문에 HTML/CSS 문제입니다. – fresskoma

+0

@ x3ro - 나는 추측하고있다. 그러나 실수로 편집을했을 때 이미 편집을하고 있었다. –

답변

-1

이 문제를 해결하려면 테이블 태그를 "Div"태그에 넣고 DIV 태그에 "style = overflow : auto"라고 지정한 "Div"태그에 특정 "height"를 지정하십시오. 스크롤 막대가 자동으로 표시됩니다.

+0

불쾌감은 없지만, 이것은 정확히 4 시간 전에 내가 대답 한 것과 정확히 일치합니다 ... 그러나 제 대답은 이해할 수있었습니다. – fresskoma

8

크기가 커질 수있는 모든 요소를 ​​래핑하고, 높이를 지정한 다음 CSS "오버플로"속성을 "스크롤"로 설정할 수 있습니다.

CSS의 overflow 속성에 대한 W3C의 tutorial을 참조하십시오.