我对 Javascript 和 JQuery 很陌生,我似乎无法弄清楚为什么一个按钮的计数器会递增,但相同的代码对其他按钮不起作用。任何帮助将不胜感激。谢谢!
// JAVASCRIPT/JQUERY (to increment by 1)
let addRoom = document.querySelector(".addRoom");
let subtractRoom = document.querySelector(".subtractRoom");
let input = document.querySelector(".roomsAmmount");
addRoom.addEventListener('click', () => {
input.value = parseInt(input.value) + 1;
});
subtractRoom.addEventListener('click', () => {
input.value = parseInt(input.value) - 1;
});
/*.addRoom,.subtractRoom{position:absolute;font-size:1.3em;width:50%;height:45px;z-index:1;display:flex}.roomsAmmount{position:absolute;width:50px;height:45px;right:-60px;border:none;border-bottom:1px solid #f4b494;outline:0;font-size:1.4em;text-align:center;background-color:transparent;color:#fff}
*/
<div class="bedroomsButton">Bedrooms
<div class="addRoom">
<span class="plusOne">+</span>
</div>
<div class="subtractRoom">
<span class="subtractOne">-</span>
</div>
<input class="roomsAmmount" type="number" value="0">
</div>
<div class="bathroomsButton">Bathrooms
<div class="addRoom">
<span class="plusOne">+</span>
</div>
<div class="subtractRoom">
<span class="subtractOne">-</span>
</div>
<input class="roomsAmmount" type="number" value="0">
</div>
子衿沉夜
蝴蝶刀刀
慕工程0101907
相关分类