Как активировать следующую вкладку и их содержимое с помощью клавиши табуляции

0

Привет, я создаю вкладки jquery, используя ul и li. Я хочу создать функцию, используя onblur, когда пользователь нажимает клавишу табуляции, она переместится на следующую вкладку. я хочу, когда пользователь в последнем текстовом поле вкладки 1, когда он нажмет клавишу табуляции, затем переместится на следующую вкладку и активирует свой контент. Я создаю вкладку, используя jquery, а не jquery ui. Я не использую индекс Tab для этого. Я хочу написать функцию onblur event.

Заметка:

 <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(); 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(); 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(); ID="test6" /></li>
                </ul>
              </div>

скрипт

$(document).ready(function () {
    alert("You are running jQuery version: " + $.fn.jquery);


    $('ul.tabs').each(function () {
        // For each set of tabs, we want to keep track of
        // which tab is active and it 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.

        if ($('hdnCurrentTabSelection.ClientID').val() == "") {
            $('#_ctl0_hdnCurrentTabSelection').val(location.hash)
        }

        $active = $($links.filter('[href="' + $('#_ctl0_hdnCurrentTabSelection').val() + '"]')[0] || $links[0]);
        $active.addClass('active');
        $content = $($active.attr('href'));
        window.location.href = window.location.href.toString().split('#')[0] + $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');
            //window.location.href = window.location.href.toString().replace($active.attr('href'), '');
            $content.hide();

            // Update the variables with the new link and content
            $active = $(this);
            $('#_ctl0_hdnCurrentTabSelection').val($active.attr("href"))
            $content = $($(this).attr('href'));
            window.location.href = window.location.href.toString().split('#')[0] + $active.attr('href');

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

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

Это скрипка

  • 1
    Как хорошо создать скрипку ...!
  • 0
    Проверьте jQuery EasyTabs, может быть, это поможет вам, а не изобретать колесо снова.
Показать ещё 3 комментария
Теги:

1 ответ

0

Я просто отправляю основной пример

jsfiddle:

http://jsfiddle.net/tsANm/1/

HTML:

      <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' class="tabclass">
            <ul class= "set2"> 
                <li>test 1<input type="text" id="test1" tabindex="1"></li>
                <li>test 2<input type="text" id="test2" tabindex="2"></li>
            </ul>
        </div>
        <div id='tab2' class="tabclass">
            <ul class= "set2"> 
                <li>test 3<input type="text" id="test3" tabindex="3"></li>
                <li>test 4<input type="text" id="test4" tabindex="4"></li>
            </ul>
        </div>
        <div id='tab3' class="tabclass">
            <ul class= "set2"> 
                <li>test 5<input type="text" id="test5" tabindex="5"></li>
                <li>test 6<input type="text" id="test6" tabindex="6"></li>
            </ul>
        </div>

CSS:

* {
    padding:0;
    margin:0;
}
html {
    padding:15px 15px 0;
    font-family:sans-serif;
    font-size:14px;
}
p, h3 {
    margin-bottom:15px;
}
div {
    padding:10px;
    width:600px;
    background:#fff;
}
.tabs li {
    list-style:none;
    display:inline;
}
.tabs a {
    padding:5px 10px;
    display:inline-block;
    background:#666;
    color:#fff;
    text-decoration:none;
}
.tabs a.active {
    background:#fff;
    color:#000;
}

JQuery:

function reset() {
    $(".tabclass").hide();
    $("#tab1").show();
    $("#test1").focus();
    $("ul.tabs li a:first").addClass("active");
}
$(function() {
    reset();    
    $("ul.tabs li a").on("click", function() {
        i=0;
        $(".tabclass").hide();
        $("ul.tabs li a").removeClass("active");
        $(this).addClass("active");
        $($(this).attr("href")).show();
    });

    var i = 0;
    var j = $(".tabclass").length;
    $("ul.set2 li input[type=text]").on("blur", function() {
        var inputFields = $(this).parents(".set2").find("input[type=text]").length;
        i++;
        if (i === inputFields) {
            var tabNum = parseInt($(this).parents(".tabclass").attr("id").toString().substring(3,4));
            $(".tabclass").hide();
            $("ul.tabs li a").removeClass("active");
            $("a[href=#" + $(this).parents(".tabclass").next().attr("id") + "]").addClass("active");
            $(this).parents(".tabclass").next().show();            
            $(this).parents(".tabclass").next().find("input[type=text]:first").focus();            
            i = 0;                       
            if (j === tabNum) {
                reset();
            }
        }
    });
});
  • 0
    спасибо за ответ @susheel, но это не соответствует моей проблеме. Я хочу, чтобы когда пользователь в последнем текстовом поле вкладки 1 нажимал клавишу табуляции, затем он переходил на следующую вкладку и активировал их содержимое. В вашем решении нет текстовых полей, более в вашем коде содержание первых вкладок не активный.
  • 0
    Вы не упомянули это ясно в своем вопросе. пожалуйста, добавьте эти строки в свой вопрос. я вернусь с вашим требуемым ответом
Показать ещё 7 комментариев

Ещё вопросы

Сообщество Overcoder
Наверх
Меню