html页面
<!doctype html><html lang="en"><head> ???<meta charset="UTF-8"> ???<meta name="viewport" ?????????content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> ???<meta http-equiv="X-UA-Compatible" content="ie=edge"> ???<title>管理员列表</title> ???<style> ???????.gre{ ???????????margin-left: 10px; ???????????background: lightgreen; ???????????border-radius: 5px; ???????????color: white; ???????????text-decoration: none; ???????} ???????.danger{ ???????????margin-left: 10px; ???????????background: red; ???????????border-radius: 5px; ???????????color: white; ???????????text-decoration: none; ???????} ???</style></head><body><table> ???<tr> ???????<th>ID</th> ???????<th>账号</th> ???????<th>班级</th> ???????<th>角色</th> ???????<th>权限</th> ???????<th>状态</th> ???????<th>操作</th> ???</tr><foreach name="list" item="v"> ???<tr id="{$v.id}"> ???????<td>{$v.id}</td> ???????<td>{$v.uname}</td> ???????<td>{$v.class_name}</td> ???????<td>{$v.rname}</td> ???????<td> ???????????<foreach name="v.nname" item="vo"> ???????????????<a href="#" style="margin-left: 10px; background: #66c9f3; border-radius: 5px;color: white;text-decoration: none;">{$vo}</a> ???????????</foreach> ???????</td> ???????<td> ???????????<if condition="$v.is_clock eq 1"><a href="javascript:void(0);" class="gre clock">正常</a> ???????????????<else /> <a href="javascript:void(0);" class="danger clock">被禁</a> ???????????</if> ???????</td> ???????<td> ???????????<a>删除</a> ???????</td> ???</tr></foreach> ???<script src="__PUBLIC__/js/jquery.js"></script> ???<script> ???????????$(‘.clock‘).on(‘click‘,function () { ???????????????var is_clock = $(this).text(); ???????????????var id = $(this).parents("td").parents().attr(‘id‘); ???????????????if(is_clock==‘正常‘){ ???????????????????var is_c = 2; ???????????????????$(this).html("被禁"); ???????????????????$(this).removeClass(‘gre‘); ???????????????????$(this).addClass(‘danger‘); ???????????????}else{ ???????????????????var is_c = 1; ???????????????????$(this).html("正常"); ???????????????????$(this).removeClass(‘danger‘); ???????????????????$(this).addClass(‘gre‘); ???????????????} ???????????????//请求 ???????????????$.get("__URL__/update_clock?is_c="+is_c+"&id="+id,function (data) { ???????????????????// alert(data); ???????????????}); ???????????}); ???</script></table></body></html>
php页面
//修改状态 ???public function update_clock(){ ???????$id = I(‘get.id‘); ???????$data[‘is_clock‘] = I(‘get.is_c‘); ???????M("user")->where("uid=".$id)->save($data); ???}
效果:
jquery+tp3实现账号是否被禁用的即点即改
原文地址:https://www.cnblogs.com/hopelooking/p/9307400.html