dpbz14739 2015-10-08 20:44
浏览 166
已采纳

我想要一个<li>,当点击时,隐藏另一个<li>在同一个<ul>中

Like the title states, I'm creating a "FAQ" section in my website where people can click an glyphicon and it will show text. Here is my code

<div class="tab-content">
    <div id="home" class="tab-pane fade in active ">
        <h3>Product Specs</h3>
        <ul id="questions">
            <li><span id="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
            <li id="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
        </ul>
    </div>
</div>

when the user clicks the <span id="symbol"> it will show/hide the

<li id="subtext">
  • 写回答

1条回答 默认 最新

  • douwaz34842 2015-10-08 20:45
    关注

    You can simply use:

    $("li:nth-child(odd) span#symbol").click(function () {
      $(this).closest("li").next("li").toggle();
    });
    

    There's something fundamentally wrong if you are using multiple ids. The ids are meant to be unique.

    So my proposal is, please change them into classes. By that way, if you do, you can do something like:

    $(function () {
      $(".subtext").hide();
      $("li:nth-child(odd) .symbol").click(function () {
        $(this).closest("li").next("li").toggle();
      });
    });
    <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <div class="tab-content">
      <div id="home" class="tab-pane fade in active ">
        <h3>Product Specs</h3>
        <ul id="questions">
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
          <li><span class="symbol"><i class="fa fa-gg"></i></span> Do I have to use one of your templates for my vinyl banner?</li>
          <li class="subtext">While we have created templates for you to use as a starting point,  if you don’t want to use them and would like to design your own banner, you have three additional options. First, you can choose the blank template and start designing from scratch on our design tool. Second, you can upload your own files to make a banner. Lastly, you can contact us and have us design something for you.</li>
        </ul>
      </div>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图