6
私はユーザーが商品ポップアップオーバーレイを更新して閉じるたびに注文受領書を更新する関数を書いています。 この関数はフォームの各入力を検索し、その値が0
より大きい場合、領収書divに情報を追加します。私は、入力フィールドの上にあるラベル要素の.html()
を取得しようとしており、現在の項目を説明し、これを領収書の項目の説明として使用します。jQueryの上からラベルを取得
私は成功せず使用して試してみました:ここ
- $this.closest('label').html()
- $this.prev('label').html()
- $this.find('label').html()
- this.element.find('label').html()
は私のコードです。私が話していますセクションでは、一部...
function updateOrder(){
var items = '';
$('input').each(function(){
var $this = $(this),
i_value = $this.attr('value');
if(i_value > 0){
items += $this.attr('id') + ' Quantity: ' + i_value + '<br/>'
+ 'label is: ' + $this.closest('label').html() + '<br/>';
}
});
$('#d_reciept').html(items);
}
とサンプルフォームアイテムのラベルである 'です
<tr>
<td class="td_thumbs">
<div>
<a class="fancybox" data-fancybox-group="vinyl-banners" href="img/products/vinyl-corporateblue.jpg"> <img src="img/products/thumbs/vinyl-corporateblue-thumb.png" alt="vinyl c-blue"/></a>
<label>Corporate Blue</label>
</div>
</td>
<td>6</td>
<td>
<input id="vinyl-blue" type="number" max="6" min="0" value="0"/>
</td>
</tr>
華麗! $(this).closest( 'tr')。find( 'label')。html()worked :) – lukeocom