[英]How to refresh jquery news ticker?
我有这个 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);
});
});
它会创建一个新元素,因为您正在使用append
。
如果你想更新页面,你应该使用.html("your code here")
或类似的函数。
这是 SM Hasibu Islam,从 2009 年到现在一直从事网络开发领域的工作。 如果您不知道如何创建 jQuery 新闻自动收报机,在下面的教程中,我将教您如何使用 HTML、CSS 和 jQuery 创建新闻自动收报机。
第1步
我已经编写了基本代码并包含了获取新闻行情所需的文件。
<!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>
第2步
第二步是添加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>
步骤:3
我们的 HTML 代码包含在我们的主要 HTML 代码中。
<!-- 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 -->
步骤:4最后,我们将 CSS 添加到 head 标签内或 body 标签上方。
<style>
#wrapper{
width:80%;
margin:0 auto;
}
.csehasibticker{
width: 550px;
height: 255px;
overflow: hidden;
border: 1px solid #eee;
border-radius: 5px;
box-shadow: 0px 0px 5px #eee;
background: #00a1e0;
color:#fff;
text-align: left;
margin:0 auto;
}
.csehasibticker h3 {
padding: 0 0 7px 7px;
border-bottom: 1px solid #444;
}
ul {
list-style: none;
padding: 0;
margin: 0;
font-style: italic;
}
ul li {
list-style: none;
height:50px;
padding:7px;
border-bottom: 1px solid #444;
}
</style>
最后,我们创建了新闻自动收报机并进行了在线测试。 请参阅如何使用 HTML CSS 和 jQuery 创建新闻行情的完整源代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.