2017-05-20 181 views
0

這裏的圖片 http://imgur.com/a/4gP06 我基本上希望 - 按鈕被直接留在「1」和+的權利「1」。 正在使用彈簧模型中的數據填充行。試圖保持在同一水平線上的兩個按鈕和段落在同一行在表

<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>Product</th> 
     <th>Quantity</th> 
     <th>Price</th> 
     <th>Total Price</th> 
     <th></th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr th:each="cartLine : ${cartLines}"> 
     <td> 
     <a th:href="@{|/product/${cartLine.product.id}|}" th:text="${cartLine.product.title}"></a> 
     </td> 
     <td> 
      <p> 
      <form th:action="@{|/cart/decrease/${cartLine.product.id}|}" method="post"> 
       <input type="submit" class="btn btn-primary" id="decreaseCartLine" value="-"/> 
      </form> 
      <p th:text="${cartLine.quantity}"></p> 
      <form th:action="@{|/cart/increase/${cartLine.product.id}|}" method="post"> 
       <input type="submit" class="btn btn-primary" id="increaseCartLine" value="+"/> 
      </form> 
      </p> 
     </td> 

     <td th:text="${cartLine.product.price}">price</td> 
     <td th:text="${cartLine.totalPrice}">total price</td> 


     <td><form th:action="@{|/cart/remove/${cartLine.product.id}|}" method="post"> 
      <input type="submit" class="btn btn-primary" id="removeCartLine" value="Remove Item"/> 
     </form> 
     </td> 
    </tr> 
    </tbody> 
</table> 

回答

0

更新

檢查演示here

而不table結構變化的內現有代碼的另一種選擇td

<td class="qtyWidth"> 
     <table> 
      <tr> 
      <td> 
       <form th:action="@{|/cart/decrease/${cartLine.product.id}|}" method="post"> 
       <input type="submit" class="btn btn-primary" id="decreaseCartLine" value="-" /> 
       </form> 
      </td> 
      <td> 
       <span class="qtyNumber" th:text="${cartLine.quantity}">11</span> 
      </td> 
      <td> 
       <form th:action="@{|/cart/increase/${cartLine.product.id}|}" method="post"> 
       <input type="submit" class="btn btn-primary" id="increaseCartLine" value="+" /> 
       </form> 
      </td> 
      </tr> 


     </table> 
     </td> 

CSS:

.qtyWidth { 
    width: 150px; 
} 
.qtyNumber { 
margin: 0 5px; 
} 

嘗試用自舉功能input-group組件

檢查工作演示here

HTML:

<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>Product</th> 
     <th>Quantity</th> 
     <th>Price</th> 
     <th>Total Price</th> 
     <th></th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr th:each="cartLine : ${cartLines}"> 
     <td> 
     <a th:href="@{|/product/${cartLine.product.id}|}" th:text="${cartLine.product.title}"></a> 
     </td> 
     <td class="qtyWidth"> 
     <div class="input-group"> 
      <span class="input-group-btn"> 
          <button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="quant[1]"> 
           <span class="glyphicon glyphicon-minus"></span> 
      </button> 
      </span> 
      <input type="text" name="quant[1]" class="form-control input-number" value="1" min="1" max="10"> 
      <span class="input-group-btn"> 
          <button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[1]"> 
           <span class="glyphicon glyphicon-plus"></span> 
      </button> 
      </span> 
     </div> 
     </td> 

     <td th:text="${cartLine.product.price}">price</td> 
     <td th:text="${cartLine.totalPrice}">total price</td> 


     <td> 
     <form th:action="@{|/cart/remove/${cartLine.product.id}|}" method="post"> 
      <input type="submit" class="btn btn-primary" id="removeCartLine" value="Remove Item" /> 
     </form> 
     </td> 
    </tr> 
    </tbody> 
</table> 

CSS:

.form-control { 
    height: auto; 
} 
.qtyWidth { 
    width: 150px; 
} 
+0

+和 - 應該是我的服務器的後請求,確保有足夠的股票等,不知道從那個例子到這樣做去哪裏 – Daniel

+0

在演示查看JS代碼。在那裏你可以根據你的需要編輯代碼,你可以通過在按鈕上使用點擊事件來獲得輸入的值,然後發出一個AJAX請求來更新它。 –

+0

不幸的是我的代碼重寫爲AJAX(還有其他的東西要更新像購物車總等)和我的控制器的發佈請求,只是讓一些按鈕保持在一行似乎不是正確的解決方案 – Daniel

0

如何將三個物品放入引導行內? 你也許可以優化這個更多,但以下似乎爲我顯示效果細膩:

<div class="container fluid" style="max-width: 200px;"> 
    <div class="row"> 
    <div class="col-4"><form th:action="@{|/cart/increase/${cartLine.product.id}|}" method="post"><input type="submit" class="btn btn-primary" id="decreaseCartLine" value="-"/></div> 
    <div class="col-4"><p th:text="${cartLine.quantity}"></p></div> 
    <div class="col-4"><form th:action="@{|/cart/increase/${cartLine.product.id}|}" method="post"><input type="submit" class="btn btn-primary" id="increaseCartLine" value="+"/></div> 
    </form></div> 
+0

它仍然是我 – Daniel

0

嘗試沒有「P」標籤。因爲,段落標籤通常佔滿。

+0

同我改一個跨度標籤,因爲我需要一個標籤爲th:text =「$ {cartLine.quantity}」,它仍然是相同的 – Daniel

+0

你能否爲我提供你的網站鏈接。對我來說,檢查是什麼讓內容換到下一行會很有幫助。 – Virushabadoss

相關問題