標籤:實現 提交 csdn 分享 資料庫 oct iss 模型 關閉
請勿盜版,轉載請加上出處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");});//監聽改動的確認改動button,並以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方式改動提交相應的那一行的改動內容。