ユーザーが購入したいチケットの数に基づいてチケットの価格を取得して表示しようとしています。コードを実行すると、最初は希望どおりに動作しますが、2 番目の数値が最初の数値を上書きします。どうすればそれらを一緒に追加できますか?
HTML:
<ul id="tickets" class="clearfix registration-form">
<li class="clearfix">
<input type="hidden" id="ticket-price" value="90">
<input class="short-input alpha number-tickets" type="number" placeholder="0" rel="#ticket-price">
<label>Number of Tickets ($90 each)<p>This is some further information about tickets, and this can be as much information as you want it to be!</p></label>
</li>
<li class="clearfix">
<input type="hidden" id="ticket-price_2" value="35">
<input class="short-input alpha number-tickets" type="number" placeholder="0" rel="#ticket-price_2">
<label>Number of Tickets ($35 each)<p>This is some further information about tickets, and this can be as much information as you want it to be!</p></label>
</li>
<li class="tickets-total">
<label>Current Total = $</label>
<input id="ticketsTotal" type="number" placeholder="0.00" readonly="true">
</li>
</ul>
Javascript:
$('input.number-tickets').keyup(function() {
$('#tickets li input[type=number]')
.not('#tickets li.tickets-total input[type=number]')
.each(function(i, data) {
var total = 0;
var priceTotal = $(this).val() * $($(this).attr('rel')).val();
for (var i=0; i < priceTotal.length; i++) {
total += priceTotal[i] << 0;
}
$('input#ticketsTotal').val(total);
})
});
ありがとう