PDO+MYSQL5.0+PHP5.4+Jquery无刷新删除和添加数据

作者在 2013-06-30 20:20:00 发布以下内容
<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>留言板</title>
<script language="JavaScript" type="text/javascript" src="jquery-1.5.1.js"></script>
<style type="text/css">
.info{width:300px;height:40px;border:1px solid red;position:absolute;margin-left:200px;margin-top:10px;display:none;background-color:#FCE8E8;font-family:"楷体_gb2312";}

</style>

</head>
<body>
<div style="border:1px solid black;width:700px;margin:auto;">
 <div class="info"></div>
  <h3>留言板</h3>
  <form action="" method="post" enctype="text/plain">
   标题:
  <input type="text" name="title" value=""/><br/>
  作者:
  <input type="text" name="author" value=""/><br/>
   内容:
  <textarea name="content" rows="10" cols="50" class="desc">
  </textarea><br/>
  <input type="button" name="btn" class="btn" value="提交"/>
</form>
<table width="600" height="50" border="1" celspacing="0" celpadding="0" style="text-align:center;">
    <tr style="background-color:#ccc;">
        <td></td>
        <td>标题</td>
        <td>作者</td>
        <td>内容</td>
    </tr>
    <?php
       include('conn.php');
       $query=$pdo->query("SELECT * FROM `new` order by `id` desc");
       while($row = $query->fetch()){

    ?>
    <tr>
    <td><input type="checkbox" name="cleck" value="<?php echo $row['id'];?>"/></td>
       <td><?php echo $row['title']?></td>
       <td><?php echo $row['autho'];?></td>
       <td><?php echo $row['content'];?></td>

    </tr>
    <?php
       }
    ?>
    <td><input type="button" value="删除" class="del"></td>
</table>
</div>
<script type="text/javascript">
			$(".btn").click(function(){
				var title=$("input:first").val();//获取匹配第一个元素,需要设置值
				var author=$("input:eq(1)").val();//匹配一个给定索引值的元素,需要设置值
				var content=$(".desc").val();
				if(title == "" || author == ""||content==""){
				 alert("文本框内容不能为空!");
				}else{
					$.post("http://127.0.0.1/test/chkfile.php",{
						title:title,
						author:author,
						content:content
					},function(data){
						$(".info").text(data).fadeIn('fast');
						//用于被追加的内容
						$("<b>请点击<a href='http://127.0.0.1/test/file.php'>刷新</a>页面<b>").appendTo(".info");
					});
				}
			});
		</script>
		<script type="text/javascript">
			$(".del").click(function(){
				var str='';
				$('[name=cleck]:checkbox:checked').each(function(){ //遍历方法
				//each:对于每个匹配的元素所要执行的函数
					str += $(this).val()+',';
					alert(str);
				});
				$.get("http://127.0.0.1/test/delfile.php",{
					str:str
				},function(data){
					$(".info").text(data).fadeIn('fast');
					$("<b>请点击<a href='http://127.0.0.1/test/file.php'>刷新</a>页面<b>").appendTo(".info");
				});
			});
		</script>
</body>
</html>



大家好,我只是写出一部分代码,这是下载源码地址:http://down.bccn.net/5669.html
php | 阅读 2062 次
文章评论,共0条
游客请输入验证码