//表單
@if($v['sex']==0)
<td class="se" ss="{{$v['sex']}}" id="{{$v['id']}}" >男</td>
@elseif($v['sex']==1)
<td class="se" ss="{{$v['sex']}}" id="{{$v['id']}}" >女</td>
@endif
//jqery
$(document).on("click",".se",function () {
id=$(this).attr("id");
sex= $(this).attr("ss");
str="";
if (sex==0){
str="男"
}else{
str="女"
}
that=$(this);
$.ajax({
url:"jdjg",
type:"post",
dataType:"json",
data:{
id:id,
sex:str
},
success:function (data) { console.log(data);
if (data=="男"){
that.text("男")
that.attr("ss",0)
} else{
that.text("女")
that.attr("ss",1)
}
}
})
})
//控制器
function jdjg(req $req){ $id= $req->post("id"); $sex=$req->post("sex");// echo json_encode($sex);die; if ($sex=="男"){ $res=DB::table("poker")->where("id",$id)->update(["sex"=>1]); $sex="女"; echo json_encode($sex); }else{ $res=DB::table("poker")->where("id",$id)->update(["sex"=>0]); $sex="男"; echo json_encode($sex); }