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()