[英]Grab the text from the nearest span tag using jquery on keyup press
我正在嘗試使用“ item_price”類從最近的span標記中獲取文本並將其保存到變量中-有人能告訴我怎么了嗎
我也試圖抓住“隱藏”的輸入
$('#ajax_basket').on('keyup','input',function(event) {
var qty = $(this).val();
var item_price = $(this).find('span.item_price').text();
var hidden_id;
console.log(qty);
console.log(item_price);
});
<form id="ajax_basket">
<table>
<tr><td><input type="hidden" name="1[rowid]" value="5333a934f53d623eb18c490b57522d93"></td></tr>
<tr>
<td>Apple iPhone 2G</td>
<td><input type="text" name="1[qty]" value="1" maxlength="2" size="1" class="input-mini qty" /></td>
<td style="text-align:right" class="item_price_row">$<span class="item_price">15.00</span></td>
<td style="text-align:right" class="sub_total">$15.00</td>
</tr>
<tr>
<td>Apple iPhone 5G</td>
<td><input type="text" name="1[qty]" value="1" maxlength="2" size="1" class="input-mini qty" /></td>
<td style="text-align:right" class="item_price_row">$<span class="item_price">115.00</span></td>
<td style="text-align:right" class="sub_total">$115.00</td>
</tr>
</tr>
</table>
</form>
您必須退后到父tr
,然后find
$('#ajax_basket').on('keyup','input',function(event) {
var qty = this.value
var item_price = $(this).closest("tr").find('span.item_price').text();
var hidden_id;
console.log(qty);
console.log(item_price);
});
下一行
$(this).find('span.item_price').text();
在文本框的后代之間使用class item_price
搜索span
。
嘗試以下操作:
$(this).parent().parent().find('span.item_price').text();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.