Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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 获取输入类型的长度=";“数字”;安格拉斯_Javascript_Html_Angularjs_Angular Material - Fatal编程技术网

Javascript 获取输入类型的长度=";“数字”;安格拉斯

Javascript 获取输入类型的长度=";“数字”;安格拉斯,javascript,html,angularjs,angular-material,Javascript,Html,Angularjs,Angular Material,因此,我看到了很多答案,但没有一个符合我的情况。我不能使用jQuery供参考 <ng-repeat="stuff in junk"> <md-input-container> <input type="number" ng-model="stuff.value.currentValue" ng-keypress="myController.checkLength(stuff.length)" 您应该使用在这种情况下可能使用的 <input ty

因此,我看到了很多答案,但没有一个符合我的情况。我不能使用jQuery供参考

<ng-repeat="stuff in junk">
  <md-input-container>
    <input type="number" ng-model="stuff.value.currentValue" ng-keypress="myController.checkLength(stuff.length)"

您应该使用在这种情况下可能使用的

<input type="number" max="9000" ng-model="stuff.value.currentValue" ng-keypress="myController.checkLength(stuff.length)" />

如果我正确理解了这个问题,那么您正在尝试将每个输入的长度设置为ng repeat中每个stuff.value.currentValue(可能是可变的)的长度。如果这是正确的,您可以尝试以下操作:

<input type="number" 
 maxlength="{{::stuff.value.currentValue.length}}"  
 ng-model="stuff.value.currentValue" 
 ng-keypress="myController.checkLength(stuff.length)" />


绑定中变量名之前的
::
表示一次绑定,这意味着该值在第一次摘要循环之后设置,在后续摘要循环之后不会更改。这意味着,当ng repeat在数据中循环时(比如“Peter”、“Paul”和“Mary”),每个输入的最大长度将是原始输入的长度(在本例中为5、4和4),并且在更新模型时不会更改。maxlength属性不会提供错误消息,但不允许用户输入长度超过每个内容原始长度的文本。value.currentValue

我不明白-为什么不能使用max<
input
元素的code>max
属性将起作用。“我只是试图进行一个数字输入,在这里我可以限制长度,而不仅仅是有一个错误告诉他们太多的字符。”
input
元素
的预期值范围是多少?有多少个字符会“太多”?没有最大值将不起作用。Max会在超出限制时提醒您,它不会停止进一步的输入。限制是不相关的,但可能是4个字符,范围是0-9999.Min,最大值只会给出一个错误,就像我说的,我正在努力限制字符的数量,而不仅仅是提醒用户。