what is the use of type = number allow to type 0123456789.Ee-+ even it returning invalid value?

陌路散爱 提交于 2019-12-23 05:19:22

问题


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=number allow 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 E

  • 1e+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 invalid value.


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!