繁体   English   中英

如何设置input:number元素更改时触发的事件?

[英]How to set event that triggered when input:number element changes?

我有这个输入数字:

    <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: <input type="number" class="form-control input-sm col-xs-2" id="txtMonth" ng-model="month" ng-change="change()" min="1" max="12"/>

Javascript:

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

请尝试一下,让我知道您的问题是否解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM