PHP记事(5)- 关于comment
2011-01-19 10:49
337 查看
查看index.php输出的html代码:
比较打开comment与不打开comment时的html源码,两者完全相同,blog entry的代码片段都为:
在Chrome里通过“检查元素”功能可以看到其实comment的代码片段应该为:
在index.htnl中有如下片段:
此为JavaScript函数,通过查找,在_cache/js/action.js文件中。有函数定义:
在Google中search$.post,发现它是JQuery函数,对comment.php发送请求,以post形式传送id与pg两个参数。然后调用function作为回调函数,它将obj的内容设定为返回的html片段。该请求将返回什么样的html片段?另外做一个实验文件postForm.html:
执行表单提交,得到的html代码为:
从模板html文件,到经过模板类编译生成最终的html文件,这个过程与其他页是完全相同的,只是这个部分被以Ajax用异步的方式动态的加载并删除到html中。
<!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="X-UA-Compatible" content="IE=EmulateIE7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Microblog</title> <meta content="phpsay,microblog" name="keywords" /> <meta content="" name="description" /> <link rel="alternate" type="application/rss+xml" href="rss.php" mce_href="rss.php" title="Microblog" /> <link rel="stylesheet" type="text/css" href="_static/default/style.css" mce_href="_static/default/style.css" /> <mce:script type="text/javascript" src="_static/js/jquery.js" mce_src="_static/js/jquery.js"></mce:script> <mce:script type="text/javascript" src="_static/js/form.js" mce_src="_static/js/form.js"></mce:script> <mce:script type="text/javascript" src="_static/js/action.js" mce_src="_static/js/action.js"></mce:script> <mce:script type="text/javascript" src="_static/js/zoomi.js" mce_src="_static/js/zoomi.js"></mce:script> </head> <body> <div id="navbar"><a href="./login.php" mce_href="login.php">登录</a></div> <div class="wrapper"> <div id="header"> <img src="_static/avatar/avatar.jpg" mce_src="_static/avatar/avatar.jpg" alt="phpsay" id="avatar" /> <h1><a href="./" mce_href="./">Microblog</a><span><a href="./" mce_href="./">http://localhost/blog</a></span></h1> <ul id="menu"> <li><a href="./" mce_href="./">微博</a></li> <li><a href="./follow.php" mce_href="follow.php">关注</a></li> <li><a href="./follow.php?t=fans" mce_href="follow.php?t=fans">粉丝</a></li> </ul> </div> <div id="description"> <span class="left"></span> <span class="right"><a href="./rss.php" mce_href="rss.php" title="RSS订阅" target="_blank"></a></span> </div> <div id="main"> <div class="entry first"> <div class="content">///</div> <div class="from"> <span class="mycome">2010年12月31日 15:16 from Web</span> <span class="option"> <span class="reply" onclick="loadComments(5)">评论 <span id="reply_5">(0)</span> </span> </span> </div> <div class="clear"></div> </div> <div class="comment" id="comment_5"></div> <div class="entry"> <div class="content">分享图片ttt<a id="zoom" href="#" mce_href="#" title="点击关闭"><img src="_static/picture/2010/12/31/s_151533_24087.jpg" mce_src="_static/picture/2010/12/31/s_151533_24087.jpg" alt= "_static/picture/2010/12/31/b_151533_24087.jpg" title="查看大图"></a></div> <div class="from"> <span class="mycome">2010年12月31日 15:15 from Web</span> <span class="option"> <span class="reply" onclick="loadComments(4)">评论 <span id="reply_4">(1)</span> </span> </span> </div> <div class="clear"></div> </div> <div class="comment" id="comment_4"></div> <div class="entry"><div class="content">d - Digits (0-9)D - Any non digit character. - (Period) – Any character except newline</div><div class="from"><span class="mycome">2010年12月31日 15:14 from Web</span><span class="option"><span class="reply" onclick="loadComments(3)">评论<span id="reply_3">(1)</span></span></span></div><div class="clear"></div> </div><div class="comment" id="comment_3"></div><div class="entry"><div class="content">W - Any non “word” characters - Whitespace (space, tab CRLF)S - Any non whitepsace character</div><div class="from"><span class="mycome">2010年12月31日 15:14 from Web</span><span class="option"><span class="reply" onclick="loadComments(2)">评论<span id="reply_2">(0)</span></span></span></div><div class="clear"></div> </div><div class="comment" id="comment_2"></div><div class="entry"><div class="content">PHP REGEX CHEAT SHEET Special Sequences /w - Any “word” character (a-z 0-9 _)</div><div class="from"><span class="mycome">2010年12月31日 15:13 from Web</span><span class="option"><span class="reply" onclick="loadComments(1)">评论<span id="reply_1">(0)</span></span></span></div><div class="clear"></div> </div><div class="comment" id="comment_1"></div> <div class="pages"><em>共 5 篇</em></div> <div id="stat">数据统计:24小时内发布<strong>0</strong>篇 ... 一周内发布<strong>0</strong>篇 ... 总发布数<strong>5</strong></div> </div> </div> <div id="footer"><span>© 2006~2010 PHPSay.com</span>Powered by <a href="http://www.phpsay.com/" mce_href="http://www.phpsay.com/" target="_blank">PHPSay-Microblog</a> 1.2 ,Theme By Hoofei<mce:script type="text/javascript"><!-- $.get('./friend_server.php?do=update'); // --></mce:script></div></body></html>
比较打开comment与不打开comment时的html源码,两者完全相同,blog entry的代码片段都为:
<div class="entry first"> <div class="content">///</div> <div class="from"> <span class="mycome">2010年12月31日 15:16 from Web</span> <span class="option"> <span class="reply" onclick="loadComments(5)">评论 <span id="reply_5">(0)</span> </span> </span> </div> <div class="clear"></div> </div> <div class="comment" id="comment_5"></div> <div class="entry"> <div class="content">分享图片ttt<a id="zoom" href="#" mce_href="#" title="点击关闭"><img src="_static/picture/2010/12/31/s_151533_24087.jpg" mce_src="_static/picture/2010/12/31/s_151533_24087.jpg" alt="_static/picture/2010/12/31/b_151533_24087.jpg" title="查看大图"></a></div> <div class="from"> <span class="mycome">2010年12月31日 15:15 from Web</span> <span class="option"> <span class="reply" onclick="loadComments(4)">评论 <span id="reply_4">(1)</span> </span> </span> </div> <div class="clear"></div> </div>
在Chrome里通过“检查元素”功能可以看到其实comment的代码片段应该为:
<div class="comment" id="comment_4" style="display: block; " mce_style="display: block; "> the cached file is effective <ul> <li id="comment_list_1"> <p>nice work!</p> <span class="from">2010年12月31日 15:20 <i>by</i> <u>good</u></span> </li> </ul> <div id="comment_div_4"> <form id="comment_form_4"> <input type="text" name="nickname" id="input_nickname_4" class="short" maxlength="10" onkeydown="if(event.keyCode==13){return false;}">: <input type="text" name="comment" id="input_message_4" class="long" maxlength="70" onkeydown="if(event.keyCode==13){commentDo(4)}"> <input type="hidden" name="mid" value="4"> <input type="submit" class="submit" id="input_submit_4" value="" onclick="commentDo(4)"> </form> </div> </div>
在index.htnl中有如下片段:
onclick="loadComments(5)"
此为JavaScript函数,通过查找,在_cache/js/action.js文件中。有函数定义:
function loadComments(id) { var obj = $("#comment_"+id); if( obj.css('display') == "none" ) { obj.html("<div class='load'><img src="./_static/images/loading.gif" mce_src="_static/images/loading.gif"></div>"); obj.slideDown("fast",function(){$.post('./comment.php', {id:id,pg:1},function(m){obj.html(m);});}); } else { obj.slideUp("fast",function(){obj.html("");}); } }
在Google中search$.post,发现它是JQuery函数,对comment.php发送请求,以post形式传送id与pg两个参数。然后调用function作为回调函数,它将obj的内容设定为返回的html片段。该请求将返回什么样的html片段?另外做一个实验文件postForm.html:
<!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>postForm</title> </head> <body> <form action="http://localhost/blog/comment.php" method="post" name="comment_form_4" target="_blank" id="comment_form_4" > <input type="text" name="nickname" id="input_nickname_4" maxlength="10">: <input type="hidden" name="id" value="4"> <input type="hidden" name="pg" value="1"> <input name="submit" type="submit" id="input_submit_4" value="sub"> </form> </body> </html>
执行表单提交,得到的html代码为:
<html> <head></head> <body> the cached file is effective <ul> <li id="comment_list_1"> <p>nice work!</p> <span class="from">2010年12月31日 15:20 <i>by</i> <u>good</u></span> </li> </ul> <div id="comment_div_4"> <form id="comment_form_4"> <input type="text" name="nickname" id="input_nickname_4" class="short" maxlength="10" onKeyDown="if(event.keyCode==13){return false;}">: <input type="text" name="comment" id="input_message_4" class="long" maxlength="70" onKeyDown="if(event.keyCode==13){commentDo(4)}"> <input type="hidden" name="mid" value="4"> <input type="submit" class="submit" id="input_submit_4" value="" onClick="commentDo(4)"> </form> </div> </body> </html>
从模板html文件,到经过模板类编译生成最终的html文件,这个过程与其他页是完全相同的,只是这个部分被以Ajax用异步的方式动态的加载并删除到html中。
相关文章推荐
- 分享一个关于php中explode()函数输出实例(简单的)
- 关于php面向对象继承方面的几点总结
- 关于下载PHP时候遇到的分类
- 关于PHP与Sybase数据库的连接与使用
- 回应拐拐龙底咚兄弟关于ROR,PHP,Web应用开发
- 关于Java的ORM及 PHP直接面向数据库关系 模式的思考
- php关于序列化和反序列化的应用
- 关于 断点续传上传与秒传 你绕不过去的坎 html5+php
- 关于php操作mysql执行数据库查询的一些常用操作汇总
- 关于PHP对discuz的支持配置。
- Facebook关于HipHop for PHP 的简短介绍(译文)
- 关于PHP中Session文件过多的问题及session文件保存位置
- 关于php smarty模版入门
- 关于PHP内存溢出问题的解决方法
- 关于几种语言(c#,php,python,javascript)字符串的gzip压缩与解压的整理
- php中关于socket的系列函数总结
- PHP4.4.2中关于BASE64编码中的一点BUG
- 关于php执行liux命令出现的问题,记载
- 关于php socket编程中遇到的一些问题
- 关于PHP变量定义赋值书写规格