Change input value onclick button - pure javascript or jQuery

前端 未结 6 1425
面向向阳花
面向向阳花 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 12:51

    using html5 data attribute...

    try this

    Html

    Product price: $500
    
    
    Total price: $500

    Total

    JS

    $(function(){
    $('input:button').click(function () {
      $('#count').val($(this).data('quantity') * $('#product_price').text());
    });
    });
    

    fiddle here

提交回复
热议问题