設定最大上輸入文本欲使用角JS如何使用角JS
如果我輸入值> 10我想旁邊的文本框中顯示錯誤消息的量字段中設置最大值。由於type =「text」,它不像數字那樣工作。
<input type="text" name="input" ng-model="example.value" ngmin="0" ngmax="10" >
設定最大上輸入文本欲使用角JS如何使用角JS
如果我輸入值> 10我想旁邊的文本框中顯示錯誤消息的量字段中設置最大值。由於type =「text」,它不像數字那樣工作。
<input type="text" name="input" ng-model="example.value" ngmin="0" ngmax="10" >
正如他們之前所說的,只是將類型更改爲「數字」。但是你可以用輸入反正做室內用控制器解析像這樣數量的功能:使用
.controller('myCtrl', function ($scope) {
$scope.parse = function(i){
return parseInt(i);
}
});
而在HTML中的NG-IF:
<input type="text" ng-model="myNum">
<p class="bad-input" ng-if="parse(myNum)>10 ||parse(myNum)<0 ">The number is wrong</p>
下面是一個工作Plunker
爲什麼不讓它輸入'type =「number」'? –
爲什麼不使用type =「number」? – mehulmpt
,然後使用'ng-if'在'example.value'爲'null'時顯示一條消息。 – Naigel