Change input value onclick button - pure javascript or jQuery

前端 未结 6 1427
面向向阳花
面向向阳花 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:06

    And here is the non jQuery answer.

    Fiddle: http://jsfiddle.net/J7m7m/7/

    function changeText(value) {
         document.getElementById('count').value = 500 * value;   
    }
    

    HTML slight modification:

    Product price: $500
    
    Total price: $500

    Total

    EDIT: It is very clear that this is a non-desired way as pointed out below (I had it coming). So in essence, this is how you would do it in plain old javascript. Most people would suggest you to use jQuery (other answer has the jQuery version) for good reason.

提交回复
热议问题