Change input value onclick button - pure javascript or jQuery

前端 未结 6 1430
面向向阳花
面向向阳花 2020-12-05 12:20

I have two buttons and if I click on some button I need to change value in input text and change total price (product price * value of button - 2 or 4 Qty).

I know

6条回答
  •  我在风中等你
    2020-12-05 13:01

    My Attempt ( JsFiddle)

    Javascript

    $(document).ready(function () {
        $('#buttons input[type=button]').on('click', function () {
            var qty = $(this).data('quantity');
            var price = $('#totalPrice').text(); 
            $('#count').val(price * qty);
        });
    });
    

    Html

      Product price:$500
    
    Total price: $500

    Total

提交回复
热议问题