我想在用户使用 Tab 键移动到下一个选项卡时创建功能。每个选项卡都包含一些文本框。当用户在选项卡1的最后一个文本框中按Tab键时,它将进入tab2的下一个文本框。我正在使用纯HTML css和jQuery创建选项卡。我没有使用jQuery UI的选项卡功能,但它是最新的jquery。下面是我的 HTML。我正在使用 ul 和 li 创建选项卡。当我的选项卡在第一个文本框中时,我如何进入下一个 li。选项卡包含下拉列表,复选框,文本框。注意:由于某些问题,我没有使用选项卡索引。我想使用 jquery 创建)为此,我编写了一个模糊函数。该模糊函数将 Tab 键移动到下一个选项卡并专注于下一个选项卡。但问题是当我们移动到下一个选项卡时,我如何同时激活选项卡及其内容
<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模拟点击选项卡与代码执行
因此,对于您的情况,可以将onblur
事件重写为:
<li> test 6<asp:TextBox runat="server"
onblur="funcation(){move(); $('#tab1').click(); }"
ID="test6" /></li>
尝试使用触发器("点击")示例:$("#tab2").trigger("click")