Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 允许输入类型中的数字范围-plunker_Javascript_Jquery_Html_Angularjs_Validation - Fatal编程技术网

Javascript 允许输入类型中的数字范围-plunker

Javascript 允许输入类型中的数字范围-plunker,javascript,jquery,html,angularjs,validation,Javascript,Jquery,Html,Angularjs,Validation,请参考plunker 如您所见,有两个输入字段,每个字段前面都有一个描述 目前,它允许用户同时允许正值和负值。我希望它只允许第一个字段中0到10范围内的正值和-1到0范围内的负值 我怎样才能在这里做到这一点?有人能帮忙吗 HTML代码 <div ng-controller="MainCtrl"> Positive from 0 to 10 only<input type="text" ng-model="amount" format="number" /><br

请参考plunker

如您所见,有两个输入字段,每个字段前面都有一个描述

目前,它允许用户同时允许正值和负值。我希望它只允许第一个字段中0到10范围内的正值和-1到0范围内的负值

我怎样才能在这里做到这一点?有人能帮忙吗

HTML代码

<div ng-controller="MainCtrl">
  Positive from 0 to 10 only<input type="text" ng-model="amount" format="number" /><br><br>

  Negative from -1 to 0 only<input type="text" ng-model="amount1" format="number" />
</div>

您可以使用HTML5输入类型

<input type="number" max="10" min="0" step="0.01" ng-model="amount" format="number" />
<input type="number" step="0.01" max="1" min="0" ng-model="amount1" format="number" />

我在github上找到了Cohen Adair发布的指令。这对我来说非常有效,我只需要在css部分上做一些工作,在这里和那里做一些工作,这样就可以将它应用到我的项目中。这里是链接


@dipesh-我尝试过,但它仍然允许我键入一个大于“最小值”和“最大值”中提到的值的数字。我想要的是,如果“最大值”设置为10,则会阻止用户键入大于10的数字。@dipesh-在我的情况下,无论输入类型是文本还是文本。因此,“最小”和“最大”不起作用。@Ayesha如果你需要数字,那么为什么要使用文本字段?@dipesh-我使用了一些指令,以便输入字段允许动态使用逗号和小数点。。。有了数字,很难得到这种类型的验证。。。
<input type="number" max="10" min="0" step="0.01" ng-model="amount" format="number" />
<input type="number" step="0.01" max="1" min="0" ng-model="amount1" format="number" />