私は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>
は、変更イベントを発生させる何かをするときにうまく機能します。 *ヒントヒント* –
あなたはjsをたくさん混ぜているようです。一貫性を維持しようとすると、document.getElementByIdは機能しますが、jqueryを使用しているので、なぜ$( "#quantity")だけではないのですか? – JonH