【问题标题】:how do i link a checkbox to a website如何将复选框链接到网站
【发布时间】:2016-03-02 02:20:03
【问题描述】:

我有以下代码:

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

有没有办法让我在点击复选框时将用户带到另一个站点?

【问题讨论】:

    标签: angularjs checkbox href


    【解决方案1】:

    另一种方法是使用ngChange directive

    <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');
    }
    

    Working fiddle

    【讨论】:

      【解决方案2】:

      使用window.location.assign():

      HTML

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

      JS 控制器

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

      【讨论】:

        【解决方案3】:

        另一种解决方案:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-12-24
          • 2015-11-01
          • 2014-03-17
          • 2018-04-29
          • 2017-11-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多