2014-12-21 19 views
-2

我有一個下面的代碼。它是一個基於$ {listStores}輸出的動態表。每行在最後一個單元格上都有一個編輯按鈕。點擊它我想獲得StoreId這是一個隱藏的元素對該行相應的行。從包含編輯按鈕的行獲取元素值

 <tbody> 
     <c:forEach items="${listOpenStores}" var="store"> 
      <tr> 
       <td class="collapsing"> 
        <div class="ui fitted checkbox"> 
         <input type="checkbox"> <label></label> 
        </div> 
       </td> 
       <td id="at-liststore-storeid-hidden" > 
        <div class="ui input"> 
         <input type="text" value="${store.storeId}"> 
        </div> 
       </td> 
       <td>${store.storeName}</td> 
       <td>${store.storeURL}</td> 
       <td> 
        <div id="at-store-edit-btn" class="ui primary icon button"><i class="pencil icon"></i></div> 
       </td> 
      </tr> 
     </c:forEach>    
    </tbody> 
+1

你試圖解決這個自己?你走多遠了?告訴我們你的代碼。 – PeterKA

+1

ID **必須**在文檔上下文中是唯一的。您呈現的HTML標記無效$ –

+0

我嘗試使用var elem = $(this).parent()。parent();但不能通過 –

回答

1

試試這個:

$(this).parent().siblings('#at-liststore-storeid-hidden').find('input').val(); 

但要重複相同的id是無效的 所以,你也可以試試這個沒有ID

$(this).parent().prev().eq(2).find('input').val(); 
+0

嘿,什麼可能是一種更好的方式來實現這種功能?如果我想讓Id的唯一性,使用id動態追加storeid是否是一個更好的主意,或者如果我想引用這個name屬性? –

+0

@上面它主要取決於你的需要,如果你的頁面不是很大或沒有ids是在數百然後存儲動態id是最好的方式來執行此任務becoz在jquery中搜索id是最快的方法,否則使用普通類也是個好主意。 – Jain