空检查这个脚本?

时间:2011-02-23 12:27:00

标签: javascript jquery jquery-plugins html

介于head

之间
<head><script type="text/javascript">$(document).ready(function() {
        $.twitter.start({
            searchType:"searchWord", 
            searchObject:"google", 
            lang:"en", 
            live:"live-180", 
            placeHolder:"tweetContainer", 
            loadMSG: "Loading messages...", 
            imgName: "loader.gif", 
            total: 6, 
            readMore: "Read it on Twitter", 
            nameUser:"image", 
            openExternalLinks:"newWindow", 

        });


    });</script></head>

介于body

之间
<body>
<div id="tweetContainer"></div>
</body>

我想对tweet容器进行空检查,好像没有推文然后隐藏Div tweetContainer

1 个答案:

答案 0 :(得分:1)

你可以这样做

if($("#tweetContainer").eq(0).html() == '')
{
  //this implies there are no tweets. so do whatever you need to
  $("#tweetContainer").hide();
}

希望这有帮助!

如果您需要定期执行此操作,那么您可以

function checkTweets()
    {
        if($("#tweetContainer").eq(0).html() == '')
        {
          //this implies there are no tweets. so do whatever you need to
           $("#tweetContainer").hide();
        }
        else
           $("#tweetContainer").show();


    }
    //fire once and then setTime out
    checkTweets();
    setTimeout(checkTweets,100);