监听事件动态改变dom状态
2024-09-05 14:05:18
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>
最新文章
- Binary Tree Preorder Traversal -- LEETCODE 144
- http请求相关
- dev_set_draw的fill和margin模式
- abap--How to debug backgroud job
- Ansible用于网络设备管理 part 2 对Jinja2 YAML 和 module的理解
- 【BZOJ 3223】文艺平衡树 模板题
- 解决visual studio已安装的问题
- easyui源码翻译1.32--DateBox(日期输入框)
- Android 性能优化 五 性能分析工具dumpsys的使用
- 错误21002:[SQL-DMO]用户";xxx";已经存在
- 玩转 SSH(一):使用 Struts 搭建简单站点
- IDL 矩阵运算
- 用python做小说网站
- 让Oracle 大小写敏感 表名 字段名 对像名
- I/O-----字符输入流
- vue 组件的定义
- (6)tcp-socket
- JavaScript大杂烩6 - 理解JavaScript中的this
- openvpn路由配置
- jmeter的使用
热门文章
- c++ pb_ds库,实现 红黑树,Splay
- python从入门到大神---Python的jieba模块简介
- faster-rcnn代码阅读-rpn-data层
- hexo中加入点击出现小红心的特效会导致无法双击选中和连续点击三次选中一整行的操作
- Codeforces 1174C Ehab and a Special Coloring Problem
- nodejs中命令行和node交互模式的区分
- liunx crontab 参数代表含义
- asp.net Core 使用redis(StackExchange.Redis)
- ie8以下不兼容h5新标签的解决方法
- 2019-7-29-C#-在基类定义好方法让子类继承接口就能实现