변경 값을 div
에 표시하려고하지만 작동하지 않습니다. 플러스와 변화를 신호하는 클릭 이벤트를 처리해야 빼기위한change not working jQuery
button_up=document.getElementById('up');
button_down=document.getElementById('down');
button_up.onclick=function() {setQuantity('up');}
button_down.onclick=function() {setQuantity('down');}
quantity = document.getElementById('quantity');
function setQuantity(upordown) {
if (quantity.value > 1) {
if (upordown == 'up'){++quantity.value;}
else if (upordown == 'down'){--quantity.value;}}
else if (quantity.value == 1) {
if (upordown == 'up'){++quantity.value;}}
else
{quantity.value=1;}
}
$('.order-option input[type=\'text\']').change(function(){
$('.show').text($('#quantity').val())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="order-option">Quantity: <span id="quantity-field">
<button id="down">-</button>
<input type="text" id="quantity" value="1">
<button id="up">+</button>
</span>
</div>
<div class="show"></div>
은 변경 이벤트를 트리거하는 작업을 할 때 잘 동작합니다. * 힌트 힌트 * –
jquery와 js를 많이 혼합하는 것 같습니다. 일종의 일관성을 유지하려고하면 document.getElementById가 작동하지만 jquery를 사용하는 이유는 단지 $ ("quantity")가 아니기 때문입니다. – JonH