How do I listen for step up event for input type=“number”

前端 未结 5 1816
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 11:45

I want to be able to listen to step UP (increment) and step down events with jQuery. (currently I can only understand how to lis

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 12:18

    I'm not sure if there is a listener of the stepUp and StepDown but you can externalize the PLUS and LESS buttons of the input number using:

    document.getElementById("myNumber").stepUp(5); //increase the value +5
    document.getElementById("myNumber").stepDown(5); // decrease the value -5
    

    So you can finally achieve your objective!

    Reference: https://www.w3schools.com/jsref/met_number_stepup.asp

    NOTE: Be aware that IE11 and EDGE doesn't implement stepUp / stepDown. On my case I just remove the + and - icon and leave only the input number field. Hope EDGE die soon...

提交回复
热议问题