<button class="btn btn-warning delCartItem" onclick="delCartItem(3)">
Delete
</button>
<button class="btn btn-warning delCartItem" onclick="delCartItem(3)">
Delete
</button>
...so on
我在製作可以刪除購物車項目的按鈕。當我點擊按鈕時如何獲取按鈕功能的索引?
而delCartItem()
的參數是產品編號。
如何獲得按鈕的索引當我點擊delCartItem()
函數中的某個按鈕時?
補充:
這是我的目的:
當我點擊按鈕=>獲得按鈕的索引 =>使用$('.item_price').eq(idx).text()
獲得購物車項目的價格
<thead>
<tr>
<th>
<h3><strong> 項目 </strong></h3></th>
<th>
<h3><strong> 商品編號 </strong></h3></th>
<th>
<h3><strong> 商品名稱 </strong></h3></th>
<th>
<h3><strong> 存貨量 </strong></h3></th>
<th>
<h3><strong> 原價 </strong></h3></th>
<th>
<h3><strong> 數量 </strong></h3></th>
<th>
<h3><strong> 小計 </strong></h3></th>
<th>
<h3><strong> 操作 </strong></h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>2</td>
<td>用mBlock玩Arduino - Starting from Scratch</td>
<td>0</td>
<td class="item_price">300</td>
<td>
<select name="cnt_item[]" class="selectpicker cnt_item" data-width="fit" data-style="btn-default" data-live-search="true"></select>
</td>
<td class="item_total_price">300</td>
<td>
<button class="btn btn-warning delCartItem" id='item1' onclick="delCartItem(this.id, 2)"> <i class="fa fa-times-circle"></i> 刪除 </button>
</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>深入淺出程式設計</td>
<td>9</td>
<td class="item_price">578</td>
<td>
<select name="cnt_item[]" class="selectpicker cnt_item" data-width="fit" data-style="btn-default" data-live-search="true"></select>
</td>
<td class="item_total_price">578</td>
<td>
<button class="btn btn-warning delCartItem" id='item0' onclick="delCartItem(this.id, 1)"> <i class="fa fa-times-circle"></i> 刪除 </button>
</td>
</tr>
</tbody>
使用'$( 「button.delCartItem」)。指數()'。 – Mohammad
我不認爲你應該得到按鈕索引來確定要刪除的產品。當構建這些按鈕時,你也應該建立完整的腳本,當按鈕被點擊。可能像這樣onclick =「delCartItem(3,0)」,第二參數只是index.determine它建立時,而不是當使用。 –
我很難理解你稱之爲按鈕的「索引」。你的意思是它在頁面上所有類似按鈕列表中的位置? –