각 입력에 대해 다른 요소를 보지 않고 한 번 제안하면 input
자체에 제목 텍스트를 특성으로 저장하십시오. title
속성이 이에 적합합니다. 그걸 염두에두고
다음 코드는 작동합니다 :
HTML : 명확성을 위해 약간 단순화
. 양식, 입력 및 요약 요소에 클래스를 추가했습니다.
<form class="order-form">
<table>
<tr>
<td><input type="number" class="quantity" title="Product 1"/></td>
</tr>
<tr>
<td><input type="number" class="quantity" title="Product 2"/></td>
</tr>
<tr>
<td><input type="number" class="quantity" title="Product 3"/></td>
</tr>
</table>
<div class="order-form-summary"></div>
</form>
자바 스크립트 :
$(function(){
// Find all of the DOM elements we're interested in:
var form = $('form.order-form'),
output = form.find('.order-form-summary'),
inputs = form.find('input.quantity');
// Bind a custom event handler to the form, that collects the titles from the
// inputs with a value > 0
form.bind('updateSummary', function(){
// Collect the titles into an array
var summaries = $.map(inputs, function(e){
var input = $(e);
if (parseInt(input.val()) > 0){
return input.attr('title');
}
});
// Update the output element's HTML with the array, joined to a string with commas.
output.html(summaries.join(', '));
});
// Fire the update event whenever chance, key-up or blur occurs on any input
inputs.on('change keyup blur', function(){form.trigger('updateSummary')});
// Fire it on load to get the correct starting values (in case any inputs are already filled)
form.trigger('updateSummary');
});
이 코드는 응축 될 수 있지만, 내가 읽을두고하는 것을 목표로했습니다. 여기에 예제가있는 바이올린이 있습니다. https://jsfiddle.net/ejwLy5x8/
수량 * 가격은 어디에서 계산합니까? – asifrc
수량 * 가격 및 클래스 runningtl 장소를 계산하는 자바 스크립트 함수가 있습니다. 그러나 수량> 0 일 경우 h6 태그 내용을 표시하는 방법을 모르겠습니다. – Palemo
계산 코드를 게시하거나 [jsfiddle] (http://jsfiddle.net)을 연결할 수 있습니까? – asifrc