2009-11-11 67 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

你爲什麼改變我的retag?這個問題與php無關,而是與你的佈局有關,因此,它是一個HTML/CSS問題。 – fresskoma 2009-11-11 09:24:17

+0

@ x3ro - 我在猜測,但他可能是錯誤的,他在編輯提交時已經在編輯它。 – 2009-11-11 09:26:49

回答

-1

爲了解決這個問題,把表格標籤放在一個「Div」標籤中,並給出你想給予的「Div」標籤的特殊「高度」,並給DIV標籤賦予「style = overflow:auto」。它會自動顯示滾動條。

+0

沒有冒犯,但這是_exactly_我​​已經回答了4個小時前...但我的回答是可以理解的。 – fresskoma 2009-11-11 14:18:54

8

你可以包裝任何可能變大的元素,指定高度,然後將css「overflow」屬性設置爲「滾動」。

有關CSS的overflow屬性,請參閱W3C的tutorial