使用控制器触发第二个选项卡上的单击

时间:2017-04-03 07:54:17

标签: javascript angularjs

触发第二个标签上的点击

  <!--HTML-->
  <tab id="tabID" heading="Second Tab">

  ///JS
  $timeout(function(){
    angular.element('#tabID a').trigger('click');
  });

如何使用属性data-target =“#tab-two”

触发标签

1 个答案:

答案 0 :(得分:2)

你应该用这个:

$timeout(function(){
   angular.element('tab a[data-target="#tab-two"]').trigger('click');
});

以下是一个例子:

$('#myTab a[data-target="#messages"]').click();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="nav nav-tabs" id="myTab">
  <li class="active"><a data-target="#home" data-toggle="tab">Home</a></li>
  <li><a data-target="#profile" data-toggle="tab">Profile</a></li>
  <li><a data-target="#messages" data-toggle="tab">Messages</a></li>
  <li><a data-target="#settings" data-toggle="tab">Settings</a></li>
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="home">Home</div>
    <div class="tab-pane" id="profile">Profile</div>
    <div class="tab-pane" id="messages">Message</div>
    <div class="tab-pane" id="settings">Settings</div>
</div>