请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1
请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1
先给大家看看图片效果,大家不要直接复制代码,这样是运行不了的,因为你们数据库和我的不一样,但是你们可以自己读读这个代码,找找对自己有用的,当然我的方法也不是最好的希望大家可以给点意见,感激不尽。
(1)点击修改图标
(2)填写修改内容
(3)点击确定修改
jquery与css代码:
<style type="text/css"> .open{ display:block; } .close{ display:none; } </style> <script language="javascript"> $(function(){ //监听修改,实现显示关闭之间的切换 $("tr").delegate("td[id='modify']","click",function(){ var id = $(this).attr('name'); $("#"+id).toggleClass("close"); }); //监听修改的确认修改按钮,并以ajax方式提交 $("td").delegate("input[name='update[]']","click",function(){ var id=$(this).parent().parent().attr('name'); var student_id1=$("input[name='student_id1']").map(function(){return $(this).val()}).get(); var date1=$("input[name='date1']").map(function(){return $(this).val()}).get(); var beforeclass_id1=$("input[name='beforeclass_id1']").map(function(){return $(this).val()}).get(); var class_id1=$("input[name='class_id1']").map(function(){return $(this).val()}).get(); var type1=$("select[name='type1']").map(function(){return $(this).val()}).get(); var remark1=$("input[name='remark1']").map(function(){return $(this).val()}).get(); $.post("/qtsc/update" ,{student_id1:student_id1[id],date1:date1[id],beforeclass_id1:beforeclass_id1[id],class_id1:class_id1[id],type1:type1[id],remark1:remark1[id]},function(data){ if(data=='班级格式错误或不存在,请检查!'){ alert(data); }else{ alert(data); location.reload(); } }); }); }); </script>
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" /> <link type="text/css" rel="stylesheet" href="/css/dmcx.css"/> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/cxjl.js"></script> <script type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script> <title>MYTITLE</title> </head> <body bgcolor="#fff"> <form method="post" name="reqForm" action="/Qtsc/delete"> <table align="center" id="rounded-corner" > <thead> <tr> <th scope="col" class="rounded-company">全选<input type='checkbox' name="allsel" onclick="check_all(this,'id[]')"/></th> <th scope="col" class="rounded">姓名</th> <th scope="col" class="rounded">学号</th> <th scope="col" class="rounded">时间</th> <th scope="col" class="rounded">最初班级</th> <th scope="col" class="rounded">最终班级</th> <th scope="col" class="rounded">学籍变动类型</th> <th scope="col" class="rounded">备注</th> <th scope="col" class="rounded-q4">修改</th> <th scope="col" class="rounded-q4">删除</th> </tr> </thead> <tbody id="cxjg"> <?php $k = 0; $class = $this->class; $beforeclass = $this->beforeclass; foreach ($res=$this->studentchange as $key=>$value){ $id=$value["id"]; $url="/qtsc/delete?id[]={$id}"; echo "<tr>"; echo "<td><input type='checkbox' name='id[]' value='".$id."'/></td>"; echo "<td>".$value['name']."</td>"."<td>".$value['student_id']."</td>"."<td>".$value['date']."</td>"."<td>".$beforeclass[$key]."</td>"."<td>".$class[$key]."</td>"."<td>".$value['type']."</td>"."<td>".$value['remark']."</td>"; echo "<td name='".$id."' id='modify'><a href='#' id='alter'><img src='/images/user_edit.png' /></a></td>"; echo '<td><a href="'.$url.'" name="delete"><img src="/images/trash.png" alt="" title="" border="0" /></a></td>'; echo "</tr>"; echo "<tr class='close' name='".$k."' id='".$id."'> <form method='post' action='/qtsc/update'> <td></td> <td><input type='hidden' name='student_id1' value='".$value['student_id']."'</td> <td>日期<input type='text' name='date1' value='".$value['date']."' class='Wdate' onclick='WdatePicker()'/></td> <td>最初班级<input type='text' name='beforeclass_id1' value='".$beforeclass[$key]."'/></td> <td>最终班级<input type='text' name='class_id1' value='".$class[$key]."' /></td> <td>学籍异动类型<select name='type1' value='".$value['type']."'> <option value='".$value['type']."'>".$value['type']."</option> <option value='转专业'>转专业</option> <option value='试读'>试读</option> <option value='休学'>休学</option> </select></td> <td>备注<input type='text' name='remark1' value='".$value['remark']."'/></td> <td></td> <td><input type='button' name='update[]' value='确定修改'/></td> <td></td> </form> </tr>"; $k++; } ?> </tbody> </table> </form> <div class="bts"> <a href="/qtsc/qtscadd" class="bt"><span class="bt_lft"></span><strong>添加记录</strong><span class="bt_r"></span></a> <a href="javascript:void(0)" onclick="isdo()" class="bt"><span class="bt_lft"></span><strong>删除所选</strong><span class="bt_r"></span></a> <!--<a href="javascript:document.reqForm.submit();" class="bt"><span class="bt_lft"></span><strong>删除所选</strong><span class="bt_r"></span></a>--> </div> </body> </html>
zend framework 在这里我只写控制器中的action,模型省略写,其他的不重要的也不写
//检查学生 public function checkstuAction(){ $stu_id=$this->getRequest()->getParam("stu_id"); $student = new Student(); $res = $student->getStudent($stu_id); $studentchange = new Studentchange(); $res3 = $studentchange->getStuchange($stu_id); $beforeclass_id = $this->getRequest()->getParam('beforeclass_id'); $class_id = $this->getRequest()->getParam('class_id'); $classes = new Classes(); $res1 = $classes->getClassid($beforeclass_id); $res2 = $classes->getClassid($class_id); if(count($res)==0&&count($res3)!=0){ echo '此学号不存在,或在学籍异动中该学生已经存在'; exit(); }elseif(count($res1)==0||count($res2)==0){ echo '班级格式错误或不存在,请检查!'; exit(); }else{ echo 'ok'; exit(); } } //修改 public function updateAction(){ //取值 $student_id1 = $this->getRequest()->getParam('student_id1'); $date1 = $this->getRequest()->getParam('date1'); $beforeclass_id1 = $this->getRequest()->getParam('beforeclass_id1'); $class_id1 = $this->getRequest()->getParam('class_id1'); $type1 = $this->getRequest()->getParam('type1'); $remark1 = $this->getRequest()->getParam('remark1'); //转化班级名为ID $classes = new Classes(); $res1 = $classes->getClassid($beforeclass_id1); $res2 = $classes->getClassid($class_id1); if(count($res1)==0||count($res2)==0){ echo '班级格式错误或不存在,请检查!'; exit(); } $data = array( 'student_id'=>$student_id1, 'date'=>$date1, 'beforeclass_id'=>$res1[0]['id'], 'class_id'=>$res2[0]['id'], 'type'=>$type1, 'remark'=>$remark1 ); $studentchange = new Studentchange(); $db = $studentchange->getAdapter(); $where = $db->quoteInto('student_id=?',$student_id1); $flag=$studentchange->update($data, $where); // $date1 = array( // 'class_id'=>$res2[0]['id'] // ); // $student = new Student(); // $db1 = $student->getAdapter(); // $where1 = $db1->quoteInto('id=?',$student_id1); // $flag1 = $student->update($data1, $where1); if(count($flag)==0){ echo '您未修改内容或填写格式错误,请检查!'; exit(); }else{ echo '修改成功!'; exit(); } }
请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1
用jquery实现隐藏列表表单的显示关闭切换以及Ajax方式修改提交对应的那一行的修改内容。
时间: 2024-10-10 07:18:15