Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.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_Angularjs_Html - Fatal编程技术网

Javascript 如何设置输入:数字元素更改时触发的事件?

Javascript 如何设置输入:数字元素更改时触发的事件?,javascript,angularjs,html,Javascript,Angularjs,Html,我有这个输入号码: <input type="number" class="form-control input-sm col-xs-2" id="txtMonth" ng-model="month" min="1" max="12"/> 当值更改时,我需要将js函数归档。如何设置在事件更改时触发的事件?您可以使用ng change指令触发您想要的任何函数 <input type="number" ng-model-options='{ debounce: 1

我有这个输入号码:

    <input type="number" class="form-control input-sm col-xs-2" id="txtMonth" ng-model="month" min="1" max="12"/> 


当值更改时,我需要将js函数归档。如何设置在事件更改时触发的事件?

您可以使用
ng change
指令触发您想要的任何函数

<input type="number"  ng-model-options='{ debounce: 1000 }' ng-change='fireFunction()' />

在大多数情况下,您不希望立即启动该函数
ng model options='{debounce:Number}'
允许您在触发处理程序之前等待

关于
debounce
:它只是不立即更新模型,而是添加指定值的延迟。作为去盎司选项

Html:

Javascript:

angular.module('yourapp', [])
.controller('yourcontroller', ['$scope', function($scope) {
      $scope.change = function() {
    /*..... Do Something Here  */
  };
}]);

请尝试此操作,并告诉我您的问题是否已解决。

您可以在元素上使用ngChange指令use ng change=“myFunction()”并在控制器上定义myFunction()