HTML5 Number Input - Always show 2 decimal places

后端 未结 15 2163
太阳男子
太阳男子 2020-11-28 05:43

Is there\'s any way to format an input[type=\'number\'] value to always show 2 decimal places?

Example: I want to see 0.00 instead of

15条回答
  •  忘掉有多难
    2020-11-28 06:48

    The solutions which use input="number" step="0.01" work great for me in Chrome, however do not work in some browsers, specifically Frontmotion Firefox 35 in my case.. which I must support.

    My solution was to jQuery with Igor Escobar's jQuery Mask plugin, as follows:

    
    
    
    
    

    This works well, of course one should check the submitted value afterward :) NOTE, if I did not have to do this for browser compatibility I would use the above answer by @Rich Bradshaw.

提交回复
热议问题