简单的新浪微博
先放代码sina.php
<!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> <style> * {margin:0; padding:0;} #ul1 {width:300px; height:300px; overflow:hidden; border:1px solid black; margin:10px auto;} #ul1 div {list-style:none; padding:2px; overflow:hidden; border-bottom:1px dashed #999; filter:alpha(opacity:0); opacity:0;} </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="move.js"></script> <script src="ajax.js"></script> <script> window.onload=function () { var oTxt1 = document.getElementById("txt1"); var oBtn = document.getElementById("btn1"); var oUl = document.getElementById("ul1"); var aLi = oUl.getElementsByTagName("div"); for(var i=0;i<aLi.length;i++) { startMove(aLi[i],{opacity:100}); } oBtn.onclick=function() { var url = "sina_post.php?act=add&content="+oTxt1.value; ajax(url,function(str){ }); var oLi = document.createElement("div"); oLi.innerHTML=oTxt1.value; var aLi = oUl.getElementsByTagName("div"); if(aLi.length<1) { oUl.appendChild(oLi); } else { oUl.insertBefore(oLi,aLi[0]); } var iHeight = oLi.offsetHeight; oLi.style.height=0; startMove(oLi,{height:iHeight},function(){ startMove(oLi,{opacity:100}); }); oTxt1.value=""; }; }; </script> </head> <body> <textarea id="txt1" rows="10" cols="40"></textarea> <input id="btn1" type="button" value="发布" /> <?php $sql="SELECT ID,CONTENT,POSTTIME FROM sina ORDER BY ID DESC"; //查询语句 mysql_connect("localhost","root",""); //找到本地的mysql 并输入root用户名 ""密码 mysql_select_db("mysql"); //在mysql数据库里查找 $res = mysql_query($sql); //执行查询语句 ?> <div id="ul1"> <?php while($row=mysql_fetch_row($res)){ ?> //遍历每行 <div><?php echo $row[1]; ?></div> //div中插入每行中第二个字段的值 <?php }?> </div> </body> </html>
sina.post.php代码:
<?php switch($_GET["act"]) { case "add": $content = $_GET["content"]; $t = time(); $sql = "INSERT INTO sina(ID,CONTENT,POSTTIME) VALUES(0,'{$content}',{$t})"; mysql_connect("localhost","root",""); mysql_select_db("mysql"); mysql_query($sql); break; } ?>
还引用了ajax.js 和 move.js文件