2015-06-17 239 views
2

我有一個input type=number用於選擇一年應該加載空:設置默認值[數字]

<input type="number" placeholder="Select year" min="1930" max="2015" required 
    ng-custom-mask="9999" /> 

當用戶通過箭頭鍵選擇年,它開始在最小值:1930 。它喜歡1980年的東西。

如何設置自定義「開始」號碼輸入[號碼]?

(任何HTML5,JavaScript的(甚至AngularJS)就好了)

回答

0

你可以只添加一個value屬性

<input type="number" placeholder="Select year" 
    min="1930" max="2015" required ng-custom-mask="9999" value="1980"/> 
+0

將是很好,但我需要的是場空負荷.. –

0

什麼是這樣的:

HTML:

<input 
    type="number" 
    placeholder="Select year" 
    min="1930" 
    max="2015" 
    required 
    ng-custom-mask="9999" 
    ng-model="points" 
    step="{{getStep()}}" /> 

在您的控制器中:

$scope.getStep = function() { 
    if (!$scope.points) { 
     return 50; 
    } 
    return 1; 
    } 
0

我有點晚,但這是可以「解決」一個解決辦法:

  1. 設置您的最小值和最大值爲相同的值,在這種情況下,1980年
  2. 在一個變化,檢查是否分鐘==最大(和最小== 1980)
  3. 如果是的話,你的最小值和最大值設置爲實際值

HMTL:

<input type="number" placeholder="Select year" min="1980" max="1980" required ng-custom-mask="9999" /> 

JQuery的:

$("input[type=number]").on("change", function(){ 
    if ($(this).attr("min") == $(this).attr("max") && $(this).attr("min") == 1980) { 
     $(this).attr("min", 1930); 
     $(this).attr("max", 2015); 
    } 
});