Jquery ui 选择任何一个列表时,如何在多个列表中选择类似的内容项?
我使用的是HTML4.01 Strict、CSS3和最新的JQuery 我在一个页面中有三个相同的列表——一个用作菜单栏,另外两个较小,显示在主页内容的两侧 我希望这样,当一个列表中的任何单个选项被选中时,它也会在其他两个列表中选择相同的选项 在这种情况下,“选择”是指类“活动选项卡”的应用[通过Jquery ui 选择任何一个列表时,如何在多个列表中选择类似的内容项?,jquery-ui,list,Jquery Ui,List,我使用的是HTML4.01 Strict、CSS3和最新的JQuery 我在一个页面中有三个相同的列表——一个用作菜单栏,另外两个较小,显示在主页内容的两侧 我希望这样,当一个列表中的任何单个选项被选中时,它也会在其他两个列表中选择相同的选项 在这种情况下,“选择”是指类“活动选项卡”的应用[通过.addClass(“活动选项卡”)] 名单如下: <ul id="lt-menu" class="shift_menu"> <li class="li_tab">Hom
.addClass(“活动选项卡”)
]
名单如下:
<ul id="lt-menu" class="shift_menu">
<li class="li_tab">Home</li>
<li class="li_tab">News</li>
<li class="li_tab">Info</li>
<li class="li_tab">Download</li>
<li class="li_tab">Contact</li>
<li class="li_tab">Shop</li>
</ul>
但到目前为止运气不好
我对JQuery非常陌生,因此非常感谢您的任何帮助。我用您的列表的3份副本尝试了这一点(我只是更改了ID),它可以工作:
$(".tab, .li_tab").click(function() {
//Disable current selection
$(".active_tab").removeClass("active_tab");
// We get the index of the <li> in the current list
// Each <li> has to be to the same index in the other lists
var index = $(this).index();
// We add the 'active_tab' class to all <li> with the same index
// Assume that all lists have the 'shift_menu' class, of modify the selector
$('.shift_menu').find('li:eq(' + index + ')').addClass("active_tab");
});
$(“.tab,.li_tab”)。单击(函数(){
//禁用当前选择
$(“.active\u tab”).removeClass(“active\u tab”);
//我们得到当前列表中的索引
//每个 都必须位于其他列表中的相同索引中
var index=$(this.index();
//我们将“active_tab”类添加到具有相同索引的所有
//假设所有列表都有修改选择器的“shift_菜单”类
$('.shift_menu').find('li:eq('+index+')).addClass(“活动_选项卡”);
});
希望它对你有用
$(".tab, .li_tab").click(function() {
//Disable current selection
$(".active_tab").removeClass("active_tab");
// We get the index of the <li> in the current list
// Each <li> has to be to the same index in the other lists
var index = $(this).index();
// We add the 'active_tab' class to all <li> with the same index
// Assume that all lists have the 'shift_menu' class, of modify the selector
$('.shift_menu').find('li:eq(' + index + ')').addClass("active_tab");
});