如何将复选框链接到网站



我有以下代码:

<input type="checkbox" id="{{ day.name }}-{{ $index }}" ng-model="slot.booked" ng-disabled="slot.booked">
        <label for="{{ day.name }}-{{ $index }}">{{ slot.time }}<br>
          <span ng-if="slot.booked">Booked</span>
          <span ng-if="!slot.booked">Available</span>
        </label>

无论如何,我可以做到这一点,以便在单击复选框时将用户带到另一个站点?

另一种方法是使用 ngChange 指令

<input type="checkbox" ng-model="confirmed" ng-change="change()" />

在控制器中:

 $scope.change = function() {
   //opens a new tab in browser
   window.open('http://stackoverflow.com/questions/35686170/how-do-i-link-a-checkbox-to-a-website', '_blank');
}

工作小提琴

use window.location.assign():

.HTML

<input ... ng-click="onclick()">

JS控制器

$scope.onclick = function() {
  window.location.assign("http://www.google.com")
};

另一种解决方案:

$scope.$watch('slot.booked', function(val){
    if(val){
       window.open('url', '_blank');
    }
});

最新更新