请选择 进入手机版 | 继续访问电脑版

弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 1347|回复: 0

【js】JS生成的动态脚本鼠标事件不响应怎么办?

[复制链接]
发表于 2020-10-25 08:38:37 | 显示全部楼层 |阅读模式
我用JS生成了一段table,并含<td class="op">多个a</td>
多个a点击可以控制编辑、删除、新建等事件
JS脚本控制事件代码如下:
$("td.op").on("click touchstart", "a", function () {
        var act = $(this).attr("act");
        var page = $("cur").attr("rel");
        if (page === undefined) { page = 1; }
        if (act === "del") { if (!confirm("确定删除此项吗?")) { return; } }
        switch ($(this).attr("method")) {
                case "ajax":
                        getinfo($(this));
                        break;
                default:
                        $.send("", $.extend({ act: $(this).attr("act"), id: $(this).attr("rel"), page: page }, qs));
                        break;
        }
});
发现无响应,经过仔细研究,由于新生成的JS,$("td.op")无法找到,这思路让我找到新的解决方案。
$(document).on("click touchstart", "td.op a", function () {
        var act = $(this).attr("act");
        var page = $("cur").attr("rel");
        if (page === undefined) { page = 1; }
        if (act === "del") { if (!confirm("确定删除此项吗?")) { return; } }
        switch ($(this).attr("method")) {
                case "ajax":
                        getinfo($(this));
                        break;
                default:
                        $.send("", $.extend({ act: $(this).attr("act"), id: $(this).attr("rel"), page: page }, qs));
                        break;
        }
});
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-3-28 21:59 , Processed in 0.082393 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表