如何通过jquery使用TABKEY移入下一个选项卡 [英] How do I move in to next tab using TABKEY via jquery

查看:48
本文介绍了如何通过jquery使用TABKEY移入下一个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to create functionality when user use tab key for moving in to next tab. Every tab contains  text boxes. When user in last text box of tab 1 when it press the tab key, it will go into next text box of tab2. due to moving it will activate thenext tab and their content. I am creating tab using plain HTML css and jQuery. I am not using tab functionality of jQuery UI but its version . The below is my HTML. I am creating tab using ul and li. The tabs contains like dropdown,checkboxes,texboxes.
Note : i am not using tabindex due to some issue. i am trying to create using jquery) for this i write a blur function.that blur function move the tabkey into next tab and focus on next tab.but the problem is that how i am active the tabs and their content at the same time when we move into next tab



<pre lang="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'>
                <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>





Jquery



Jquery

$(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'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.

       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's default click action
           e.preventDefault();
       });
   });







演示在这里

http://jsfiddle.net/raji627/4n5fL/9/ [ ^ ]

推荐答案

(< span class =code-sdkkeyword> document )。ready( function (){
alert( 您正在运行jQuery版本: +
(document).ready(function () { alert("You are running jQuery version: " +


.fn.jquery);
.fn.jquery);


' ul.tabs')。each( function (){
// 对于每组标签,我们想跟踪
// 哪个标签处于活动状态及其相关内容
var
('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


这篇关于如何通过jquery使用TABKEY移入下一个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆