问题
var app = angular.module("myShoppingList", []);
app.controller("myCtrl", function($scope) {
$scope.addMe="";
});
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
</head>
<body>
<div ng-app="myShoppingList" ng-controller="myCtrl">
<input type="number" ng-model="addMe">
<p>{{addMe}}</p>
</body>
</html>
Actually input type = number does not allow most of the special characters to enter. But it's only allowing to enter + and - and (Adding and subscription) even why it does not allowing to enter / and * (divide and multiply).
And also the input field value will be invalid while we entering - and + in the input box
I am not sure this problem occurred from browser or Html because I got some details from this answer for 0123456789.Ee-+ are all legal characters according to Chrome. But I have checked with this in IE 11 browser as well which is getting this same problem. So we have an idea about input type = number should allow - and + like 0123456789.Ee-+ value But i don't know what is the use to allow this characters?
My main question is why the
type=numberallow to enter those character then why it's returning invalid value? if the input box returning invalid value then why it's allowing to type those charterers ?? What is the Use? Use?
回答1:
I got it for why it is allowing those chars. here is the use of . e + -
1e1 = 10// use of e or E1e+1 = 10// use of +1e-1 = 0.1// use of -1.1 = 1.1// use of .
So this is the reason for type=number is allowing to type those characters. And if we typing wrongly then only it's will be return
invalidvalue.
You can check those in below snippet for those values.
var app = angular.module("myShoppingList", []);
app.controller("myCtrl", function($scope) {
$scope.eorE=1e1;
$scope.float=1.1;
$scope.plus=1e+1;
$scope.mins=1e-1;
});
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
</head>
<body>
<div ng-app="myShoppingList" ng-controller="myCtrl">
<input type="number" ng-model="eorE">
<input type="number" ng-model="float">
<input type="number" ng-model="plus">
<input type="number" ng-model="mins">
<p>{{addMe}}</p>
</body>
</html>
来源:https://stackoverflow.com/questions/49250250/what-is-the-use-of-type-number-allow-to-type-0123456789-ee-even-it-returning