Jquery 附加内容 - 不可点击 [英] Jquery Appended Content - Not Clickable

查看:25
本文介绍了Jquery 附加内容 - 不可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 JQ.它基本上是添加一个小图标,允许在选择列表项时进行一些内联​​编辑.但是,我无法使用 jquery 添加的内容.当我单击 JQ 添加的内容时,我什至无法将任何内容记录到控制台.我下面的代码有问题吗?

I have the following JQ. It's basically adding a little icon that will allow for some inline editing when a list item is selected. However, I am unable to work with the jquery added content. I cant even log anything to console when I click my JQ added content. Is there something wrong with my code below?

我无法添加小提琴,因为我没有此列表正在使用的 Kendo UI 库的链接.

I can not add a fiddle, because I dont have a link to the Kendo UI libraries, that this list is using.

  <script>
                $(function () {
                    $("#treeview-left li").click(function () {
                            $("div#EditEntity").remove();
                            $(this).find(".k-state-focused").append("<div id='EditEntity'>&nbsp;&nbsp;<a href='#' id='EditWindow'  class='icon-pencil active tiny'></a></div>");
                    });
                    $(".k-state-selected").on("click", "a#EditWindow", function (e) {
                        e.preventDefault();
                        $.get("ClassificationEditEntity", function (data) {
                            $(".k-window-content").html(data);
                        });
                    });
                });

            </script>

推荐答案

你需要委托事件 因为 html 是在 DOM 加载后动态添加的:

you need delegated event as html is dynamically added after DOM load:

$(".k-state-focused").on("click", "a#EditWindow", function (e) {
  console.log("Asdf");
  $.get("ClassificationEditEntity", function(data) {
    $(".k-window-content").html(data);
  });
});

或:

$(document).on("click", "a#EditWindow", function (e) {
      console.log("Asdf");
      $.get("ClassificationEditEntity", function(data) {
        $(".k-window-content").html(data);
      });
    });

请参阅此处 委托事件详情.

See HERE at the last of the page details of delegated events.

这篇关于Jquery 附加内容 - 不可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆