我有一个显示/隐藏效果,但是我只需要能够在页面中多次使用它即可。当前,它切换所有元素。我无法理解该怎么做。
希望能对您有所帮助。
http://pastebin.me/29328e556caf53e9a1925030d65b864b
最佳答案
您可以对此进行一些编辑,它可以独立地在每个<ul>
上运行:
$('.facet ul').each(function() {
if($(this).children('li:gt(9)').hide().length === 0) return;
$(this).append(
$('<li id="toggler">More</li>').toggle(function() {
$(this).text('Hide').siblings().show();
}, function() {
$(this).text('More').siblings('li:gt(9)').hide();
}));
});
See a working demo here
以前,它得到的任何
li
都超过9,您想像上面的示例一样使用<ul>
每个.each()
元素执行此操作。关于jquery - jQuery切换以在多个实例中工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2546029/