触发选择选项单击时的功能

时间:2017-05-02 12:39:21

标签: javascript html angularjs

我想从选择框中触发该功能。我有两个选项week1和week2。如果我更改选项选项week1它将触发function.again如果我点击相同的week1选项我想调用相同的函数。

JSFiddle demo

<div ng-controller="MyCtrl">
 <select ng-model="select_value" ng-change="change()">
  <option value ="1" ng-click="change()">Week 1</option>
  <option value ="2">Week 2</option>
 </select>
  <div>counter = {{counter}}</div>
   </div>



 var myApp = angular.module('myApp',[]);
 function MyCtrl($scope) {
  $scope.counter = 1;
  $scope.change = function () {
   alert('change');
  };
 }

1 个答案:

答案 0 :(得分:0)

由于ng-change仅在值更改时触发 ,因此当您点击<select>中相同值的2倍时,不会触发它。

您可以改为使用ng-click

<option ng-click="change()" value="1">Week 1</option>

Forked your Fiddle