Javascript 如何刷新jquery新闻代码?
我有一个js,它将在我的jsp页面中显示一个新闻标签。 我将如何更新它?我尝试插入一个setTimeout,但每次刷新它时,它都会创建一个新的新闻代码。。 我的代码Javascript 如何刷新jquery新闻代码?,javascript,jquery,Javascript,Jquery,我有一个js,它将在我的jsp页面中显示一个新闻标签。 我将如何更新它?我尝试插入一个setTimeout,但每次刷新它时,它都会创建一个新的新闻代码。。 我的代码 $('document').ready(function init(){ var url = "http://localhost:8080/RestartSpringRestService/rest/getAllSiteLatestCriticalParams"; var i = 1; $.getJSON(url, fun
$('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。
如果你想更新页面,你应该使用像.htmlyour code here或类似的函数。这是S M Hasibu Islam,从2009年到现在一直在web开发领域工作。如果您不知道如何创建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>
最后,我们创建了news ticker并进行了在线测试。请参阅的完整源代码。html也在做同样的事情。