html 页面
<td class="textcenter">
<input type="text" name="cat[order]" value="{$vo.order}" class="hy_input orders" orderid="{$vo.cat_id}" style="width:50px;" /></td>
js 页面
<script type="text/javascript">
$(".orders").change(function(){
var orderid = $(this).attr('orderid');
var ordernum = $(this).val();
$.post("{:U('Image/listorder')}",{"orderid":orderid,"ordernum":ordernum},function(data){
if(data.code==1000){
location.replace(location);
}else{
alert(data.msg);
}
},"json");
});
</script>
php页面:
/**
* 排序操作
*/
public function listorder(){
if(IS_POST){
$orderid = I("post.orderid",'','intval');
$ordernum = I("post.ordernum",'','intval');
if(empty($orderid)){
$ini=array(
'code'=>222,
'msg'=>'id不合法'
);
$this->ajaxReturn($ini);
}
$listresult = M('Cat')->where("cat_id={$orderid} and status=0")->find();
if(empty($orderid)){
$ini=array(
'code'=>223,
'msg'=>'id已失效'
);
$this->ajaxReturn($ini);
}
$arr =array();
$arr['order'] = $ordernum;
$result = M('Cat')->where("cat_id={$orderid}")->save($arr);
if($result){
$ini=array(
'code'=>1000,
'msg'=>'操作成功'
);
}else{
$ini=array(
'code'=>224,
'msg'=>'操作失败'
);
}
$this->ajaxReturn($ini);
}
}