html代码:

<table class="table table-striped">
<thead>
<tr> <th>分类ID</th>
<th>父ID</th>
<th>分类名称</th>
<th>分类状态</th>
<th>分类操作</th>
</tr>
</thead>
<tbody>
{foreach name="listcat" item="c"}
<tr>
<td>{$c.cat_id}</td>
<td>{$c.fid}</td>
<td>{$c.cat_name}</td>
<td>
{if condition="$c.is_show eq 1"}
<button class="btn btn-primary openclose">显示</button>
{elseif condition="$c.is_show eq 0" /}
<button class="btn btn-restore openclose">隐藏</button>
{/if}
</td>
<td>
<a href="{:url('Index/Category/delcat',array('cat_id'=>$c['cat_id']))}"><span class="fa fa-check text-navy">删除</span></a>
<a href="{:url('Index/Category/upcat',array('cat_id'=>$c['cat_id']))}"><span class="fa fa-check text-navy">编辑</span></a>
</td>
</tr>
{/foreach}
</tbody>
</table>

JS代码:

<script type="text/javascript">
//不能监听动态的 只能监听静态的 监听document或者body或者td等
$("td").on('click','.openclose',function () {
var cat_id = $(this).parents('tr').find('td').eq(0).text();
// console.log(cat_id);
var show = $(this).text();
var is_show = '';
if (show=='显示'){
is_show ='1';
} else if(show=='隐藏'){
is_show = '0';
}
// console.log(is_show);
var td = $(this).parents('tr').find('td');
$.ajax({
type:"POST",
async:false,
data:{"cat_id":cat_id,"is_show":is_show},
url:"{:url('Index/Category/changeStatus')}",
error:function () {
console.log('error');
},
success:function (data) {
console.log(data);
if (data=='0'){
td.eq(3).html("<button class=\"btn btn-restore openclose\">隐藏</button>\n");
} else if (data=='1'){
td.eq(3).html("<button class=\"btn btn-primary openclose\">显示</button>\n");
}
}
})
})
</script>

最新文章

  1. Binary Tree Preorder Traversal -- LEETCODE 144
  2. http请求相关
  3. dev_set_draw的fill和margin模式
  4. abap--How to debug backgroud job
  5. Ansible用于网络设备管理 part 2 对Jinja2 YAML 和 module的理解
  6. 【BZOJ 3223】文艺平衡树 模板题
  7. 解决visual studio已安装的问题
  8. easyui源码翻译1.32--DateBox(日期输入框)
  9. Android 性能优化 五 性能分析工具dumpsys的使用
  10. 错误21002:[SQL-DMO]用户&quot;xxx&quot;已经存在
  11. 玩转 SSH(一):使用 Struts 搭建简单站点
  12. IDL 矩阵运算
  13. 用python做小说网站
  14. 让Oracle 大小写敏感 表名 字段名 对像名
  15. I/O-----字符输入流
  16. vue 组件的定义
  17. (6)tcp-socket
  18. JavaScript大杂烩6 - 理解JavaScript中的this
  19. openvpn路由配置
  20. jmeter的使用

热门文章

  1. c++ pb_ds库,实现 红黑树,Splay
  2. python从入门到大神---Python的jieba模块简介
  3. faster-rcnn代码阅读-rpn-data层
  4. hexo中加入点击出现小红心的特效会导致无法双击选中和连续点击三次选中一整行的操作
  5. Codeforces 1174C Ehab and a Special Coloring Problem
  6. nodejs中命令行和node交互模式的区分
  7. liunx crontab 参数代表含义
  8. asp.net Core 使用redis(StackExchange.Redis)
  9. ie8以下不兼容h5新标签的解决方法
  10. 2019-7-29-C#-在基类定义好方法让子类继承接口就能实现