jQuery附加内容-不可点击 [英] Jquery Appended Content - Not Clickable
问题描述
我有以下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'> <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>
推荐答案
您需要 已授权事件 ,因为DOM加载后会动态添加html:
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屋!