我正忙着使用我正在开发的代码来显示10个杂志,这些杂志是从xml文件中提供的。我在某种程度上工作,FF和IE7 + 8不喜欢它,可能因为它说第62行有一个错误 - 是调用数据的核心函数。
这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="robots" content="noindex, nofollow" />
<title>Brave Creative - Online Archive</title>
<link rel="stylesheet" href="css/global.css" media="screen" />
<script type="text/javascript" charset="UTF-8" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "issues.xml",
dataType: "xml",
success: function(xml) {
var shelf = $('#shelf-items');
var startIndex = 0;
var howMany = 10;
var $issues = $(xml).find('issue');
var totalIssues = $issues.length;
var numPages = Math.ceil(totalIssues / howMany)
$('span.issuecount').html(+totalIssues+' Issues - '+numPages+' Pages');
var displayIssues = function() {
var $issuesPaginated = $issues.slice( startIndex , (totalIssues - startIndex) + howMany );
$('#shelf-items li').fadeOut(500);
$issuesPaginated.each(function(){
var id = $(this).attr('id');
var date = $(this).find('date').text();
var cover = $(this).find('cover').text();
var issue = $(this).find('issuenumber').text();
var url = $(this).find('url').text();
$('<li id="'+id+'"></li>').html('<a href="'+url+'"><img src="images/covers/'+cover+'" alt="" /></a><br />'+date+' - #'+issue+'').fadeIn(500).appendTo(shelf);
});
}
$('#prevIssueButton').click(function() {
if( startIndex < howMany) {
startIndex -= howMany;
displayIssues();
}else {
startIndex = 0;
displayIssues();
$('span.error').html('No Issues to Display - You are now on Page 1').fadeIn(300).fadeOut(3000);
}
});
$('#nextIssueButton').click(function() {
if( startIndex + howMany <= totalIssues) {
startIndex += howMany;
displayIssues();
}else {
$('span.error').html('No Issues to Display - You are now on Page 1').fadeIn(300).fadeOut(3000);
startIndex = 0;
displayIssues();
}
});
displayIssues().fadeIn(500);
}
}); // end ajax call
}); // end document-ready
</script>
</head>
<body>
<div id="bc-publish"><span></span></div>
<br />
<div id="wrapper">
<header>
<h1>Online Archive: <span>FSM</span></h1>
</header>
<section id="buttons">
<a href="#" id="prevIssueButton" title="Toggle Previous Entries">Previous</a>
<a href="#" id="nextIssueButton" title="Toggle Next Entries">Next</a>
<span class="error"><a></a></span>
<div class="clear"></div>
</section> <!-- /buttons -->
<section id="shelf">
<ul id="shelf-items"></ul>
<div class="clear"></div>
</section> <!-- /shelf -->
<br />
<span class="issuecount"></span>
<br /><br />
<span class="logo"><a href="http://www.bravecreative.co.uk" title="Brave Creative"><img src="images/brave-creative-logo.jpg" alt="Brave Creative" /></a></span>
<span class="address">
<span>t.</span> 01733 392978 <span>m.</span> 07719442825<br />
<span>e.</span> tony@bravecreative.co.uk<br />
4 Milnyard Square, Orton Southgate, Peterborough PE2 6CX
</span>
<div class="clear"></div>
</div> <!-- /wrapper -->
</body>
</html>
上一个和下一个按钮无法正常工作,例如我点击下一步然后我转到第2页,再次点击下一步 - 它的空白,然后点击最后一次我被告知我没有更多的结果可供查看。但是,如果我点击之前的开始并返回3次(再次开始)然后点击下一步我可以循环回到相同的问题,这真的让我感到困惑,任何帮助都将深表感谢!
答案 0 :(得分:0)
只是阅读你的代码我有一些评论。
此:
$('span.issuecount').html(+totalIssues+' Issues - '+numPages+' Pages');
在'totalIssues'之前应该没有'+',还是我错过了什么?
$('span.issuecount').html(totalIssues+' Issues - '+numPages+' Pages');
结束
$('<li id="'+id+'"></li>').html('<a href="'+url+'"><img src="images/covers/'+cover+'" alt="" /></a><br />'+date+' - #'+issue+'').fadeIn(500).appendTo(shelf);
似乎是在错误的顺序做事,不是吗?先褪色然后追加到?
此
$('#prevIssueButton').click(function() {
if( startIndex < howMany) {
startIndex -= howMany;
displayIssues();
看起来也很奇怪,如果startIndex确实小于howMany,那么此调用后startIndex将为负数,是否有意?
然后我不确定将所有代码都放在Ajax调用的成功事件处理程序中是个好主意。我会把这些东西分开,但也许你已经尝试过并决定了这一点。这只是一个想法。