用jquery实现隐藏列表表单的显示关闭切换以及Ajax方式改动提交相应的那一行的改动内容。
Posted claireyuancy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用jquery实现隐藏列表表单的显示关闭切换以及Ajax方式改动提交相应的那一行的改动内容。相关的知识,希望对你有一定的参考价值。
请勿盗版,转载请加上出处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方式改动提交相应的那一行的改动内容。的主要内容,如果未能解决你的问题,请参考以下文章