【发布时间】:2014-01-17 12:31:11
【问题描述】:
您好,我正在使用 ul 和 li 创建一个 jquery 选项卡。我想在用户按下 tab 键时使用 onblur 创建一个函数,它将移至下一个选项卡。我想当用户在选项卡 1 的最后一个文本框中按下选项卡键时,它将移动到下一个选项卡并激活其内容。我正在使用 jquery 而不是 jquery ui 创建选项卡。我没有为此使用标签索引。我想写一个函数 onblur 事件。
注意:
<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'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();
});
});
【问题讨论】:
-
如何制作小提琴......!
-
看看jQuery EasyTabs也许会帮助你,而不是再次发明轮子。
-
@RoySchoep 在 jQuery 简单选项卡中没有选项卡键的事件
-
您可以以编程方式单击选项卡
$('#tab1').click()并打开该选项卡的内容。这就是你想要的吗? -
我没有在标签上进行活动。当用户最后输入类型时,它将调用将激活下一个选项卡和内容的函数。请仔细阅读问题
标签: javascript jquery html