javascript - 我如何使用模糊功能进入下一个选项卡

标签 javascript jquery html css tabs

我想在用户使用 tab 键移动到下一个选项卡时创建功能。每个选项卡都包含一些文本框。当用户在tab 1 的最后一个文本框按下tab 键时,它将进入tab 2 的下一个文本框。我正在使用纯 HTML css 和 jQuery 创建选项卡。我没有使用 jQuery UI 的选项卡功能,但它是最新的 jquery。以下是我的 HTML。我正在使用 ul 和 li 创建选项卡。当我在第一个文本框中选择标签时,我如何进入下一个 li。选项卡包含下拉菜单、复选框、文本框。注意:由于某些问题,我没有使用 tabindex。我想使用 jquery 创建) 为此我写了一个模糊函数。那个模糊函数将标签键移动到下一个标签并关注下一个标签。但问题是当我们进入下一个标签时我如何同时激活标签及其内容

 <ul class='tabs'>
            <li><a href='#tab1'>Tab 1</a></li>
            <li><a href='#tab2'>Tab 2</a></li>
            <li><a href='#tab3'>Tab 3</a></li>
          </ul>
          <div id='tab1'>
            <ul class= "set2"> 
                <li>  test 1<asp:TextBox runat="server"  ID="test1" /></li>
                <li>  test 2<asp:TextBox runat="server" onblur=move() ID="test2" /></li>
            </ul>
          </div>
          <div id='tab3'>
            <ul class= "set2"> 
                <li>  test 3<asp:TextBox runat="server"  ID="test3" /></li>
                <li>  test 4<asp:TextBox runat="server"  onblur=move() ID="test4" /></li>
            </ul>
          </div>
          <div id='tab3'>
            <ul class= "set"> 
                <li>  test 5<asp:TextBox runat="server"  ID="test5" /></li>
                <li>  test 6<asp:TextBox runat="server" onblur=move() ID="test6" /></li>
            </ul>
          </div>

-脚本-

  $(document).ready(function(){
        $('ul.tabs').each(function(){
        // For each set of tabs, we want to keep track of
        // which tab is active and it's associated content
        var $active, $content, $links = $(this).find('a');

        // If the location.hash matches one of the links, use that as the active tab.
        // If no match is found, use the first link as the initial active tab.
        $active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
        $active.addClass('active');
        $content = $($active.attr('href'));

        // Hide the remaining content
        $links.not($active).each(function () {
        $($(this).attr('href')).hide();
    });

        // Bind the click event handler
        $(this).on('click', 'a', function(e){
        // Make the old tab inactive.
        $active.removeClass('active');
        $content.hide();

        // Update the variables with the new link and content
        $active = $(this);
        $content = $($(this).attr('href'));

        // Make the tab active.
        $active.addClass('active');
        $content.show();

        // Prevent the anchor's default click action
        e.preventDefault();
    });
     });

最佳答案

您可以通过以下方式模拟选项卡上的点击:

$('#tab1').click();

这里有一个类似的问题:jQuery simulate click on tab with code execution

因此对于您的情况,onblur 事件可以重写为:

<li>  test 6<asp:TextBox runat="server" 
              onblur="funcation(){move(); $('#tab1').click(); }" 
              ID="test6" /></li>

关于javascript - 我如何使用模糊功能进入下一个选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21087378/

相关文章:

html - 最大化 CSS 表格单元格宽度

javascript - 将 javascript var 传递到 iframe

javascript - rails 4 : change boolean value with ajax remotely

javascript - window.location.href 窗口未在 JavaScript 中定义

jquery - 正则表达式仅匹配字母、数字和空格

javascript - 动态选择要分离的特定子div

php - 单击编辑按钮时,必须在表单中填写相应的详细信息以进行编辑

css - 强制将 div 与上层 div 对齐

jquery - 水平向左/向右滚动时翻转的 div

javascript - MongoDB Schema 优化以保存用户联系人