Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何正确使用带有setInterval函数的Jquery easyTicker?_Jquery - Fatal编程技术网

如何正确使用带有setInterval函数的Jquery easyTicker?

如何正确使用带有setInterval函数的Jquery easyTicker?,jquery,Jquery,我正在使用jqueryeasyticker插件来显示实时滚动新闻 我的要求是,每隔5秒钟,我将从后端(ajax调用)获取最新数据,并更新livenews div 我面临的问题是div数据在5秒后消失 这是我的密码 var latestnewsresponse = [ { "title": "Reliance Power Q2 net up 37% at Rs 346 crore", "pub_date": "2015-11-03 08:48",

我正在使用jqueryeasyticker插件来显示实时滚动新闻

我的要求是,每隔5秒钟,我将从后端(ajax调用)获取最新数据,并更新livenews div

我面临的问题是div数据在5秒后消失

这是我的密码

var latestnewsresponse = [
    {
        "title": "Reliance Power Q2 net up 37% at Rs 346 crore",
        "pub_date": "2015-11-03 08:48",
        "link": "http://www.business-standard.com/article/companies/reliance-power-q2-net-up-37-at-rs-346-crore-115110300604_1.html"
    },
    {
        "title": "Buy Jubilant Life; target of Rs 578: P Lilladher",
        "pub_date": "2015-11-03 08:39",
        "link": "http://www.moneycontrol.com/news/recommendations/buy-jubilant-life-targetrs-578-p-lilladher_3920361.html"
    },
    {
        "title": "Sensex, Nifty volatile; Amtek Auto up 17%, LT most active",
        "pub_date": "2015-11-03 08:30",
        "link": "http://www.moneycontrol.com/news/local-markets/sensex-nifty-volatile-amtek-auto17-lt-most-active_3947741.html"
    },
    {
        "title": "Reliance Power Q2 net up 37% at Rs 346 crore",
        "pub_date": "2015-11-03 08:48",
        "link": "http://www.business-standard.com/article/companies/reliance-power-q2-net-up-37-at-rs-346-crore-115110300604_1.html"
    }

];

displaylivenews();

setInterval(displaylivenews, 5000); 

function displaylivenews()
{
    var s = "";
    for (var i = 0; i < latestnewsresponse.length; i++)
    {
        s += '<li><div class="itemTitle"><a href="' + latestnewsresponse[i].link + '"  target="_">' + latestnewsresponse[i].title + "</a></div>";
        s += '<div class="itemDate">' + latestnewsresponse[i].pub_date + "</div>";
        mysource = latestnewsresponse[i].link.split("://")[1].split('/')[0].replace(/(www.)|(.com)/g, '');
        s += '<div class="Source">' + mysource + "</div>";
        s += '</li>'
    }
    $("#livenewsRss").html("<ul class='feedEkList'>" + s + "</ul>").easyTicker(
    {
        direction: 'up'
    });
}
var latestnewsresponse=[
{
“标题”:“信实电力第二季度净增长37%,达到3.46亿卢比”,
“发布日期”:“2015-11-03 08:48”,
“链接”:http://www.business-standard.com/article/companies/reliance-power-q2-net-up-37-at-rs-346-crore-115110300604_1.html"
},
{
“标题”:“购买欢乐生活;目标为578卢比:利拉德尔”,
“发布日期”:“2015-11-03 08:39”,
“链接”:http://www.moneycontrol.com/news/recommendations/buy-jubilant-life-targetrs-578-p-lilladher_3920361.html"
},
{
“标题”:“Sensex,俏皮易变;Amtek Auto上涨17%,LT最活跃”,
“发布日期”:“2015-11-03 08:30”,
“链接”:http://www.moneycontrol.com/news/local-markets/sensex-nifty-volatile-amtek-auto17-lt-most-active_3947741.html"
},
{
“标题”:“信实电力第二季度净增长37%,达到3.46亿卢比”,
“发布日期”:“2015-11-03 08:48”,
“链接”:http://www.business-standard.com/article/companies/reliance-power-q2-net-up-37-at-rs-346-crore-115110300604_1.html"
}
];
displaylivenews();
设置间隔(displaylivenews,5000);
函数displaylivenews()
{
var s=“”;
对于(var i=0;i”+s+””).easyTicker(
{
方向:“向上”
});
}


你现在能告诉我如何解决这个问题吗?

我注意到的第一件事是当函数第二次运行时,
easyticker
插件将
#livenewsRss
的高度设置为0。因此,我将插件中的高度设置为函数第一次运行时设置的高度(216像素)

当我让它在第二次执行时停止消失后,我注意到它没有循环。我认为这可能与插件的第一个实例从未被破坏有关。因此,我采纳了的建议,在
displaylivenews()的开头添加了
$.removeData($(“#livenewsRss”).get(0))
函数终止插件实例的任何以前版本

下面是新的
displaylivenews()
函数

function displaylivenews()
{
    $.removeData($("#livenewsRss").get(0));
    var s = "";
    for (var i = 0; i < latestnewsresponse.length; i++)
    {
        s += '<li><div class="itemTitle"><a href="' + latestnewsresponse[i].link + '"  target="_">' + latestnewsresponse[i].title + "</a></div>";
        s += '<div class="itemDate">' + latestnewsresponse[i].pub_date + "</div>";
    mysource = latestnewsresponse[i].link.split("://")[1].split('/')[0].replace(/(www.)|(.com)/g, '');
        s += '<div class="Source">' + mysource + "</div>";
        s += '</li>'
    }
    $("#livenewsRss").html("<ul class='feedEkList'>" + s + "</ul>").easyTicker(
    {
        direction: 'up',
        height: '216'
    });
}
函数displaylivenews()
{
$.removeData($(“#livenewsRss”).get(0));
var s=“”;
对于(var i=0;i”+s+””).easyTicker(
{
方向:'向上',
高度:'216'
});
}

这里有一个。

您可能需要修改插件或寻找具有所需功能的插件。您并没有破坏内部间隔,而是在元素上存储数据并调整样式。