type = number有什么用途允许输入0123456789.Ee- +即使它返回无效值? [英] what is the use of type = number allow to type 0123456789.Ee-+ even it returning invalid value?

查看:119
本文介绍了type = number有什么用途允许输入0123456789.Ee- +即使它返回无效值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre-class =snippet-code-js lang-js prettyprint-override> var app = angular.module(myShoppingList,[]); app.controller(myCtrl,function ){$ scope.addMe =;});

< HTML>< HEAD> < link rel =stylesheethref =style.css> < script src =https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js>< / script>< / head>< body> < div ng-app =myShoppingListng-controller =myCtrl> < input type =numberng-model =addMe> < p为H. {{ADDME}}< / p为H. < / body>< / html>

code> type = number 不允许大多数特殊字符输入。但它只允许输入 +和 - 和(添加和订阅),甚至为什么它不允许输入 /和*(除法和乘法)



此外,在输入 - 和+ 在输入框中



我不确定这个问题是由浏览器还是Html发生的,因为我从 0123456789.Ee - + 均为符合Chrome浏览器的合法字符 。但我已经在IE 11浏览器中检查过这个问题,它也遇到了同样的问题。所以我们有一个关于 input type = number should allow - and + like 0123456789.Ee - + value但是我不知道有什么用允许这些字符?


我的主要问题是为什么 type = number 允许输入这些字符,那么为什么它返回无效值?如果输入框返回无效值,那么为什么它允许键入那些租船人?什么是使用? 使用



解决方案

为什么它允许这些字符。这里是使用。 e + -




  • 1e1 = 10 //使用e或E


  • 1e + 1 = 10 //使用+


  • 1e-1 = 0.1 //使用 -


  • 1.1 = 1.1 //使用。





所以这就是type = number允许键入这些字符的原因。如果我们打错了,那么只会返回无效值。







您可以在下面的代码片段中查看这些值。



var app = angular.module(myShoppingList,[]); app.controller( myCtrl函数($ scope){$ scope.eorE = 1e1; $ scope.float = 1.1; $ scope.plus = 1e + 1; $ scope.mins = 1e-1;}); < html>< head>< p> < link rel =stylesheethref =style.css> < script src =https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js>< / script>< / head>< body> < div ng-app =myShoppingListng-controller =myCtrl> < input type =numberng-model =eorE> < input type =numberng-model =float> < input type =numberng-model =plus> < input type =numberng-model =mins> < p为H. {{ADDME}}< / p为H. < / body>< / html>

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?

解决方案

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>

这篇关于type = number有什么用途允许输入0123456789.Ee- +即使它返回无效值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆