【问题标题】:How to get the selected tab names in jquery如何在jquery中获取选定的选项卡名称
【发布时间】:2013-09-10 12:07:08
【问题描述】:

这是我的小提琴http://jsfiddle.net/LTpL6/

HTML:

<ul class="tabs_down_link">
    <li ><a style="   padding: 7px 14px;font-size: 16px; color: #000; border-   bottom:1px solid #FFFFFF;"  href="#view_down7">Subject Area-Based Citations</a></li>
                                                            <li ><a    href="#view_down8">Sub-Area Based Citations</a></li>
      </ul>

 <div class="tabcontents_down_link">
 <div id="view_down7" style="line-height:180%; font-size: 14px;font-weight: bold;  color: #808080; ">
                                                                <input   type="checkbox" />&nbsp;(SciCI)<br/>
                                                                <input   type="checkbox" />&nbsp;(SS&HCI)<br/>
                                                                <input  type="checkbox" />&nbsp; (M&HSCI) <br/>
                                                                <input  type="checkbox" />&nbsp;(LSciCI)<br/>

 </div>

  <div id="view_down8" style="font-weight: bold;line-height:180%; font-size: 14px; color: #808080;">
                                                                <input    type="checkbox" />&nbsp;History Citation Index<br/>
                                                                <input  type="checkbox"/>&nbsp;Religion Citation Index<br/>
                                                                <input   type="checkbox" />&nbsp;Biotechnology Citation Index<br/>
                                                                <input  type="checkbox" />&nbsp;Food Science Citation Index<br/>
                                                                <input  type="checkbox" />&nbsp;Chemistry Citation Index<br/>
                                                                <input  type="checkbox" />&nbsp;Mathematics Citation Index<br/>
                                                                <input  type="checkbox" />&nbsp;Neuroscience Citation Index<br/>

                                                            </div>
                                                        </div>

Javascript:

   $(document).ready(function () {
       $('div[id^=view_down]').hide();
       $('#view_down7').show();
       $('.tabs_down_link a').click(function () {
           var tab_id = $(this).attr('href');
           var now = $(this).attr('.tabs_down_link a');
           $('div[id^=view_down]').hide();
           $(tab_id).show(); 
       });
   });

这里一切正常。

现在有两个标签 1.Subject Area-Based Citations 2.Sub-Area Based Citations

有一个通用 div,用户在其中单击任何特定选项卡,内容将显示在该通用 div 中,现在它显示正确,但我需要根据单击的选项卡更改选项卡名称。

所以现在默认是基于主题区域的引文选项卡,因此当用户尝试单击基于子区域的引文时,选项卡名称“基于子区域的引文”应自动出现在第一个默认选项卡中。

如何做到这一点,请帮忙。

【问题讨论】:

  • 我要删除答案...这将非常混乱,因为您必须跟踪先前单击的标题及其目标等

标签: javascript jquery html css tabs


【解决方案1】:

只需将此代码添加到您的 $('.tabs_down_link a').click() 函数中,它就会相应地更改选项卡名称。

var newName =  $(this).text();
    $(this).text($('#selected-tab').text());
   $('#selected-tab').text(newName);

此代码将互换第一个选定选项卡和选定选项卡的名称。不要忘记将 id "selected-tab" 赋予第一个选项卡。

【讨论】:

  • 看看这个小提琴jsfiddle。你的项目的分支......猜猜这就是你想要的?
  • 是的,兄弟,但现在 div 部分无法正常工作。
  • 当我单击第一个选项卡时再次没有,div 部分没有改变
  • 你可以自己检查一两次兄弟,你可以识别,内容不会自动改变
  • 点击选项卡时,选项卡会发生变化,但选项卡内的内容不会自动更改。请帮忙。
猜你喜欢
  • 2019-11-30
  • 1970-01-01
  • 2010-10-09
  • 2013-09-12
  • 2010-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-05
相关资源
最近更新 更多