我有文本框,其值爲1的數字類型。我想要在jQuery中獲取此文本框的值。如何通過jQuery中的ID獲取文本框的輸入值
<input type="number" value="1" name="quantity" class="form-control quantity" id="<?= $product_id ?>" />
jQuery的
<script>
$(document).ready(function(){
$('.add_cart').click(function(){
var quantity = $('#' + product_id).val();
alert(quantity);
});
</script>
這裏的問題是,如果我點擊添加到購物車用默認值(即1)我收到警報爲1,但如果增加文本框的值價值我仍然得到警報爲1.它不應該發生我想獲得遞增或遞減值。任何人都可以請我。
從你從哪裏得到的product_id –
它來自數據庫 –
我的意思是在你的jQuery代碼,你'product_id' –