js代码
<script>
function changeOrd(obj, id) {
var val = obj.text();
var c = obj.parent("td");
obj.parent("td").html("<input type='text' style='width:50px;' onFocus=this.select() onblur=changeOrdConfirm($(this)," + id + ") value='" + val + "' />");
c.children("input").focus();
}
function changeOrdConfirm(obj, id) {
var ord = obj.val();
$.post("pxgx", {
id:id,
ord: ord
}, function(data) {
obj.parent("td").html("<a onclick=changeOrd($(this)," + id + ")>" + obj.val() + "</a>");
})
}
</script>
htm标签代码
<td align="center">
<a onclick="changeOrd($(this), '{$vo.id}')">{$vo.sort}</a></td>
后端控制器代码
function pxgx(){
if (request()->isPost()){
$data=input('post.');
$pxgx=db('cate')->where('id',$data['id'])->update(['sort'=>$data['ord']]);
if ($pxgx) {
return $this->success('更新排序成功', 'lst');
} else {
return $this->error('更新排序失败', 'lst');
}
}
}