使用一个导航标签实现控制多个标签内容

时间:2016-09-28 10:48:12

标签: javascript jquery css tabs materialize

我的问题与此问题非常相似:Control multiple tab-contents with one nav-tabs

就像那个问题中的那个,我想用一个标签点击更改两个id的容器。不同之处在于我使用了物化CSS。

这是我的HTML:

    <div class="row">
     <div class="col s12">
      <ul class="tabs">
        <li class="tab col s3"><a href="#test1">Test 1</a></li>
        <li class="tab col s3"><a class="active" href="#test2">Test 2</a></li>
        <li class="tab col s3"><a href="#test3">Test 3</a></li>
        <li class="tab col s3"><a href="#test4">Test 4</a></li>
      </ul>
     </div>
     <div class="col s12">
      <div id="test1" class="col s12">Test 1</div>
      <div id="test2" class="col s12">Test 2</div>
      <div id="test3" class="col s12">Test 3</div>
      <div id="test4" class="col s12">Test 4</div>
     </div>
   </div>
   <div class="row">
    <div class="col s12">
      <div id="test1a" class="col s12">Test 1A</div>
      <div id="test2a" class="col s12">Test 2A</div>
      <div id="test3a" class="col s12">Test 3A</div>
      <div id="test4a" class="col s12">Test 4A</div>
    </div>
  </div>

这里是小提琴:Jsfiddle

当我点击TEST1时,我希望内容为TEST1和TEST1A。等

谢谢!

1 个答案:

答案 0 :(得分:1)

请在html下面试试

HTML CODE:
    <div class="row">
        <div class="col s12">
          <ul class="tabs">
            <li class="tab col s3"><a href="#test1,#test1a">Test 1</a></li>
            <li class="tab col s3"><a class="active" href="#test2,#test2a">Test 2</a></li>
            <li class="tab col s3"><a href="#test3,#test3a">Disabled Tab</a></li>
            <li class="tab col s3"><a href="#test4,#test4a">Test 4</a></li>
          </ul>
        </div>
        <div class="col s12">
          <div id="test1" class="col s12">Test 1</div>
          <div id="test2" class="col s12">Test 2</div>
          <div id="test3" class="col s12">Test 3</div>
          <div id="test4" class="col s12">Test 4</div>
        </div>
      </div>
    <div class="row">
        <div class="col s12">
          <div id="test1a" class="col s12">Test 1A</div>
          <div id="test2a" class="col s12">Test 2A</div>
          <div id="test3a" class="col s12">Test 3A</div>
          <div id="test4a" class="col s12">Test 4A</div>
        </div>
      </div>