简体   繁体   English

jQuery load(),然后在所加载的内容上使用hide()

[英]jQuery load(), then use hide() on what's loaded

I'm loading a series of <li> s and would then like to hide all but the first 9... I'm using: 我正在加载一系列<li> ,然后要隐藏除前9个之外的所有内容...我正在使用:

$(document).ready(function() {
    $("#myList").load("tweet-list.php");
    var refreshId = setInterval(function() {
        $("#myList").load('tweet-list.php', function() {
            $('#myList li:gt(8)').hide();
        });
    }, 120000);
   $.ajaxSetup({ cache: false });
}); 

But I cannot get the $('#myList li:gt(8)').hide(); 但是我无法获得$('#myList li:gt(8)').hide(); part to work, and so the entire file shows... I imagine I need to use .live() but I'm not sure what event to use. 部分起作用,因此整个文件都会显示...我想我需要使用.live(),但是我不确定要使用哪个事件。 Any help would be greatly appreciated! 任何帮助将不胜感激!

I recommend loading them as hidden, and then explicitly showing the ones you want to see. 我建议将它们加载为隐藏状态,然后显式显示要查看的内容。 The .hide() function runs asynchronously, and you could end up with some weirdness. .hide()函数异步运行,您最终可能会感到有些奇怪。

$('#myList li').filter(function(){ return $(this).index()>8; }).hide();

例如

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM