我正在顯示來自div的數據庫中的數據。顯示的div的數量取決于數據庫記錄。每個div都有一個表單,其中包含隱藏的輸入和Submit按鈕。當我單擊Submit按鈕時,我應該只從該div的隱藏輸入中獲取數據。問題是我僅從第一個div獲取數據。HTML<div class="col-md-4 col-sm-4" th:each="product : ${products}"> <!--card --> <div class="card" style="margin-bottom: 10px;"> <span th:if="${products.empty}" style="color: #0e4377">No Products Available</span> <!-- Card image --> <div class="view overlay"> <img class="card-img-top" alt="productImage" th:attr="src=${product.image}" height="100px" width="50px" > </div> <!-- Card image --> <div class="card-body" > <!-- Title --> <h4 class="card-title" th:text="${product.name}"></h4> <!-- Text --> <span> <i class="fas fa-dollar-sign"></i> <p class="card-text" th:text="${product.price}">$</p> </span> <!--button container--> <div class="button-container" > <!-- Button --> <form action="#" th:object="${Product}" method="POST" > <input type="hidden" th:value="${product.id}" name="id" class="id"/> <input type="hidden" th:value="${product.name}" name="name" class="name"/> <input type="hidden" th:value="${product.image}" name="image" class="image"/> <input type="hidden" th:value="${product.price}" name="price" class="price"/> <input type="hidden" th:value="${session.userId}" name="userId" class="userId"/> <button type="submit" class="btn btn-info btn-sm" onclick="addToCart();">Add</button> </form> </div> <!--button container--> </div> </div>
如何使用Jquery在按鈕單擊頁面上的多個div中的div中以div的形式獲取數據
慕田峪7331174
2021-05-19 17:13:32