如何刷新jquery新闻自动收报机?

时间:2014-07-30 08:05:22

标签: javascript jquery

我有这个js,它会在我的jsp页面中显示新闻自动收录器。 我该如何更新?我尝试插入一个setTimeout,但每次刷新它都会创建一个新的新闻自动收录器.. 我的代码..

$('document').ready(function init(){

var url =     "http://localhost:8080/RestartSpringRestService/rest/getAllSiteLatestCriticalParams";
var i = 1;
$.getJSON(url, function(data){

       $.each(data, function(i, item) {  
               alert("hiii::"+":::::::"+item.bufferCount+":::::::"+item.cpu+":::::::"+item.memory);
              $("#news ul").append("").append("").append("").append("").liScroll();
              i++;
        });
//           refresh ticker
       setTimeout(init,1000);
});
});

2 个答案:

答案 0 :(得分:1)

它会创建一个新元素,因为您使用的是append 如果您想更新页面,则应使用.html("your code here")或类似功能。

答案 1 :(得分:0)

这是S M Hasibu Islam,从2009年到现在,从事网络开发工作。如果你不知道如何创建一个jQuery新闻自动收录器,在风箱教程中,我将教你如何使用HTML,CSS& amp; jQuery的。

步骤:1

我已经编写了基本代码并包含了获取新闻自动收报机视图所需的文件。

<parameter name="SO_TIMEOUT">120000</parameter>

步骤:2

第二步是添加HTML代码。

    <!DOCTYPE html>
<html>
    <head>
        <title>My jQuery News Ticker</title>
        <script type="text/javascript" src=" http://code.jquery.com/jquery-2.2.3.js "></script>
    </head>
 <body>
 </body>
</html>

步骤:3

我们的HTML代码包含在我们的主HTML代码中。

<div class=“csehasibticker”>
   <h3>Breaking News</h3>
   <ul id=“csehasibticker”>
       <li>Lorem Ipsum is simply dummy text of the printing and typesetting industry...</li>
       <li>Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s</li>
<ul>
    <li>Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC...</li>
</ul>
<ul>
    <li>There are many variations of passages of Lorem Ipsum available...</li>
</ul>
<ul>
       <li>All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary...</li>
</ul>
</div>

步骤:4 最后,我们将CSS添加到head标签内或正文标签上方。

<!-- Include jQuery function -->
    <script type="text/javascript">
        function csehasibticker() {
            jQuery('#csehasibticker li:first').slideUp(function() {
               jQuery(this).appendTo($('#csehasibticker')).slideDown();
            });
        }
       setInterval(csehasibticker, 4000);
    </script>
<!-- //Include jQuery function -->

最后,我们创建了新闻自动收报机&amp;在线测试。请参阅 How to Create News Ticker Using HTML CSS and jQuery

的完整源代码
相关问题