最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to input hours and minute in angular js ? - Stack Overflow

programmeradmin0浏览0评论

This is code

<input type="number" class="form-control" min="0" max="12" step="1" ng-model="input.hours" required>
<input type="number" class="form-control" min="0" max="60" step="5" ng-model="input.minute" required>

This is browser preview

I need to input hours as 08 and minutes 05 But visible 8 and 5. How can do that?

If not clear, ment. Hope answer soon.

This is code

<input type="number" class="form-control" min="0" max="12" step="1" ng-model="input.hours" required>
<input type="number" class="form-control" min="0" max="60" step="5" ng-model="input.minute" required>

This is browser preview

I need to input hours as 08 and minutes 05 But visible 8 and 5. How can do that?

If not clear, ment. Hope answer soon.

Share Improve this question asked Sep 11, 2015 at 12:51 Amila SampathAmila Sampath 6454 gold badges11 silver badges28 bronze badges 3
  • 2 Is there a reason not to use <input type=time>? – Blindy Commented Sep 11, 2015 at 12:53
  • Feel free to accept an answer if any of them helped you out. – Chrillewoodz Commented Sep 11, 2015 at 18:52
  • @Blindy maybe because it is not supported in Safari or Internet Explorer 12 and earlier versions – Sebastien Commented Jan 26, 2021 at 9:51
Add a ment  | 

2 Answers 2

Reset to default 6

You can use ng-change to insert a 0 before the value each time it changes:

<input type="number" class="form-control" min="0" max="12" step="1" ng-model="input.hours" required ng-change="onChange(input.hours)">
<input type="number" class="form-control" min="0" max="60" step="5" ng-model="input.minute" required ng-change="onChange(input.minute)>

$scope.onChange = function(val) {

  if (val < 10) {
    val = '0' + val;
  }
}

I would suggest to create a filter to add '0' before number if needed

https://stackoverflow./a/17648547/274500

发布评论

评论列表(0)

  1. 暂无评论