最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to hide an element when certain tabs is shown - Stack Overflow

programmeradmin1浏览0评论

I am using Twitter Bootstrap, and had successfully implemented the tabs. I have a button that should display on all the tabs except for one, any idea how should I do that?

<div class="span6 offset1"> 
  <div class="tabbable">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#general" data-toggle="tab">General</a></li>
      <li><a href="#example2" data-toggle="tab">Example2</a></li>
      <li><a href="#example3" data-toggle="tab">Example3</a></li>
    </ul>

    <div class="tab-content">
      <div id="general" class="tab-pane fade in active" >
       //content
      </div>
      <div id="example2" class="tab-pane fade" >
       //content
      </div>
      <div id="example3" class="tab-pane fade" >
       //content
      </div>
    </div>
 </div> 
 <input type="submit" style="width:120px" class='btn btn-primary' id="update" value="Update"/> 
</div>

How do I program it such that when tab example3 is shown, the update button will be hidden, but still remains on page when tab general and example2 is shown.

Thanks!

I am using Twitter Bootstrap, and had successfully implemented the tabs. I have a button that should display on all the tabs except for one, any idea how should I do that?

<div class="span6 offset1"> 
  <div class="tabbable">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#general" data-toggle="tab">General</a></li>
      <li><a href="#example2" data-toggle="tab">Example2</a></li>
      <li><a href="#example3" data-toggle="tab">Example3</a></li>
    </ul>

    <div class="tab-content">
      <div id="general" class="tab-pane fade in active" >
       //content
      </div>
      <div id="example2" class="tab-pane fade" >
       //content
      </div>
      <div id="example3" class="tab-pane fade" >
       //content
      </div>
    </div>
 </div> 
 <input type="submit" style="width:120px" class='btn btn-primary' id="update" value="Update"/> 
</div>

How do I program it such that when tab example3 is shown, the update button will be hidden, but still remains on page when tab general and example2 is shown.

Thanks!

Share Improve this question edited Feb 27, 2020 at 17:39 isherwood 61.2k16 gold badges122 silver badges170 bronze badges asked Apr 19, 2012 at 9:39 revolverrevolver 2,4055 gold badges25 silver badges40 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

I am not sure that is there any event being fired in bootstrap tabs. But the simplest way can be to use mouseclick event on example3 link or even you can try to trigger custom event.

$('a[href="#example3"]').on('click',function(){
 $("#update").hide();
});

use .style.display = 'none'

e.g.

document.getElementById(id).style.display = 'none';
发布评论

评论列表(0)

  1. 暂无评论