html代码
1 <table class="easyui-datagrid" data-options="singleSelect:true,collapsible:true,method:'get'"> 2 <thead> 3 <tr> 4 <th data-options="field:'itemid'">编号</th> 5 <th data-options="field:'productid'">标题</th> 6 </tr> 7 {foreach name="cooperation" item="vo" key="k"} 8 <tr> 9 <th data-options="field:'name'" width="100">{$vo.id}</th> 10 11 <th data-options="field:'size'"> 12 <button class="btn btn-primary btn-lg" value="{$vo.id}" id="aaa" onclick="upd(this)">修改</button> 13 </tr> 14 {/foreach} 15 16 17 </thead> 18 </table>
html模态框
1 <div id="upd" class="easyui-window" title="Modal Window" style="700px; height:500px" data-options="modal:true,closed:true,iconCls:'icon-save'"> 2 <form action="{:url('Admin/index/upd')}" method="post"> 3 <input type="text" id="updid" name="updid"> 4 upd标题:<input type="text" name="table" id="table"/> 5 <input type="submit" value="Submit" /> 6 </form> 7 </div>
在js中
1 function upd(obj){ 2 var content = obj.value; 3 4 $.ajax({ 5 type:'get', 6 url:"{:url('admin/index/upd')}", 7 data:{id:content}, 8 success:function(data){ 9 var a=eval(data); 10 // console.log(a); 11 $('#table').val(a[0]['table']); 12 $('#content').val(a[0]['content']); 13 $('#updid').val(content); 14 if(data){ 15 16 // $('#wu-dialog').dialog('close'); 17 } 18 else{ 19 //绑定值 20 $('#wu-form').form('load', data); 21 } 22 } 23 24 }) 25 26 $('#upd').form('clear'); 27 $('#upd').dialog({ 28 closed: false, 29 modal:true, 30 title: "添加信息", 31 }); 32 }
在控制器中写:
1 public function upd(){ 2 if($_GET){ 3 $id = $_GET['id']; 4 $Shop_details = hinkDb::table('cooperation'); 5 $shuju = $Shop_details->where("id = $id")->select(); 6 echo json_encode($shuju); 7 } else { 8 $table = input("table"); 9 $content = input("content"); 10 $id=input("updid"); 11 $updi = hinkDb::table('cooperation')->where('id',"$id")->update(array("table"=>$table,"content"=>"$content")); 12 if($updi==1){ 13 $this->success("修改成功,正在跳转详情页面"); 14 } else { 15 $this->success("修改失败,正在跳转详情页面"); 16 } 17 } 18 }
效果是:点击修改后弹出模态框,模态框中input中带有值,然后点击提交就修改ok了