JavaScript - js翻页遍历json数据

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title >网站 </title>
< meta name ="keywords" />
< meta name ="description" />
</head>
< body >
< br /> < div id ="area" >
< div id ="area_left" >
</div>
< div id ="area_right" >
< div class ="title" >
< img src ="http://www.jquryajax.com/images/xwzx_gfxw_title.jpg" width ="728" height ="47" id ="title_img" /> </div>
< div class ="con" >
< div class ="bottom" >
< div class ="dh" > < img src ="http://www.jquryajax.com/images/news_dh.jpg" width ="712" height ="43" border ="0" /> </div>
< div id ="news_list" >
< center > < font color ="#D8B99A" >正在加载数据... </font> </center>
</div>
< div id ="page" > </div>
</div>
</div>
</div>
< div class ="clear" > </div>
</div>
< div style =" width:1000px;margin:0 auto;" > </div>
< script language ="javascript" type ="text/javascript" >
function getNews(startIndex,catId)
{
location = "getJson2.html?startIndex="+startIndex+"&catId="+catId;
}
function showNewsList(json,catId){
var list = [];
var news = json.items;
if(0==news.length){
list.push(" < center > < font color=\"#D8B99A\" > 对不起没有找到您想要的数据! </font> </center>");
}
for (var i in news){
list.push(" < div class=\"text\" >");
list.push(" < div class=\"text_left\" > < a href=\"content.html?newsId="+news<i >.newsId+"\" class=\"cD8B99A\">"+news < i >.newsTitle+" </a> </div>");
list.push(" < div class=\"text_right\" >"+news < i >.createTime+" </div>");
list.push(" < div class=\"clear\" > </div>");
list.push(" </div>");
}
document.getElementById("news_list").innerHTML = list.join('');
var page = [];
if(0<news.length){
page.push(" < a href=\"javascript:getNews(0,catId)\" class=\"font2_11\" >第一页 </a>    ");
page.push(" < span > < a href=\"javascript:getNews("+json.previousIndex+",catId)\" class=\"font2_11\" >上一页 </a> </span>    ");
page.push(json.index+'/'+json.pageCount+'    ');
page.push(" < span > < a href=\"javascript:getNews("+json.nextIndex+",catId)\" class=\"font2_11\" >下一页 </a> </span>    ");
var endpage = 0;
if(json.endPage>0){
endpage = json.endPage;
}
page.push(" < a href=\"javascript:getNews("+endpage+",catId)\" class=\"font2_11\" >最后一页 </a> </span> </center>");
}
document.getElementById("page").innerHTML = page.join('');
}
var url = window.location.href;
var m = url.indexOf("startIndex=");
var n = url.indexOf("&",m+11);
var j = url.indexOf("catId=");
var k = url.indexOf("&",j+6);
var startIndex=0;
var catId=503;
if(m>=0)
{
startIndex = n>m?url.substring(m+11,n):url.substring(m+11);
}
if(j>=0)
{
catId = k>j?url.substring(j+6,k):url.substring(j+6);
}
if(catId==505)
{//商务活动
document.getElementById("title_img").src = "http://www.jquryajax.com/images/xwzx_swhd_title.jpg";
type=505;
}
else if(catId==502)
{//官方新闻
type=502;
document.getElementById("title_img").src = "http://www.jquryajax.com/images/xwzx_gfxw_title.jpg";
}
else if(catId==504)
{//专题活动
type=504;
document.getElementById("title_img").src = "http://www.jquryajax.com/images/xwzx_zthd_title.jpg";
}else if(catId==503){//系统公告
type=503;
document.getElementById("title_img").src = "http://www.jquryajax.com/images/xwzx_xtgg_title.jpg";
}else if(catId==521){//媒体报道
type=521;
document.getElementById("title_img").src = "http://www.jquryajax.com/images/xwzx_mtbd_title.jpg";
}
var SPL = [];
SPL.push('http://localhost:8080/webnews-mysql/visitSpringContext.jsp');
$LJ(SPL);
setTimeout("showNewsList(json"+catId+","+catId+")",2000);
</script>
</body>
</html>

你可能感兴趣的:(JavaScript,js,json,数据,遍历)