angularJS: how to revert / prevent radio button event?

前端 未结 2 1788
面向向阳花
面向向阳花 2021-01-13 03:40

i have a (non-working) example in http://jsfiddle.net/S2kc7/1/




        
2条回答
  •  [愿得一人]
    2021-01-13 04:18

    You can make it work by using ng-change. Make sure that each radio has the ng-change on it

    
    
    
    

    And you can use this logic in your controller

    $scope.value= $scope.preval= 'foo';
    $scope.validateChange = function() {
        if(confirm('revert???  value='+$scope.value+'  preval='+$scope.preval)) {
            $scope.preval = $scope.value;
        } else {
            $scope.value = $scope.preval;
        }
    };
    

    Updated and working fiddle http://jsfiddle.net/S2kc7/3/

提交回复
热议问题