日期:2014-05-16  浏览次数:20374 次

js,关于父子页面,关于内嵌函数,求帮助
不知道这种内嵌函数怎么写,function prevPage()被我写成了这个样子,谁能告诉我该怎么写?或者是有别的问题?
function displayPosts(){
with(parent.bottomFrame.document){
open();
writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
        writeln('        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
        writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">');
        writeln('<head>');
        write('<meta http-equiv="Content-Type" ');
        writeln('content="text/html; charset=ISO-8859-1" />');
        writeln('<title>MicroBlog Display</title>');
writeln('<script type="text/JavaScript">');

// You may write any legal JavaScript statements here within write() or writeln()
// This is prevPage function()
writeln('function prevPage(){ ');
writeln('alert("prevPage called: Array length: " + parent.topFrame.posts.length);');
// You need to fill in here...
// ...
pageNum--;
writeln('if(posts.length-5*pageNum>=0){');
writeln('for (var i = posts.length - 1-5*(pageNum-1); i > posts.length - 6-5*(pageNum-1); i--) {');
writeln('writeln('<tr><td align="center">' + posts[i].date + '</td>');');
writeln('writeln('<td align="center"><img src="' + posts[i].mood + '" name="mood" /></td>');');
writeln('writeln('<td align="left">' + posts[i].content + '</td>');');
writeln('writeln('<td align="center">');');
writeln('writeln('<button onclick="deletePost()">Delete</button></td></tr>');');

writeln('else');
writeln('for (var i = posts.length - 1-5*(pageNum-1); i > -1; i--) {');
writeln('writeln('<tr><td align="center">' + posts[i].date + '</td>');');
writeln('writeln('<td align="center"><img src="' + posts[i].mood + '" name="mood" /></td>'); ');
writeln('writeln('<td align="left">' + posts[i].content + '</td>');');
writeln('writeln('<td align="center">');');
writeln('writeln('<button onclick="deletePost()">Delete</button></td></tr>');');
writeln('}');

writeln('}');

// This is nextPage function()
writeln('function nextPage(){');
writeln('alert("nextPage called: Array length: " + parent.topFrame.posts.length);');
// You need to fill in here...
writeln('}');

// This is deletePost function()
writeln('function deletePost(){');
writeln('alert("deletePost called: Array length: " + parent.topFrame.posts.length);');
// You need to fill in here...
writeln('}');


writeln('</script>');