2014-07-24 77 views
0

我有以下JQ。它基本上是添加一個小圖標,當選擇一個列表項目時,可以進行一些內聯​​編輯。但是,我無法使用jquery添加的內容。當我點擊我的JQ添加內容時,甚至無法記錄任何內容。我的代碼在下面有什麼問題嗎?jquery附加內容 - 不可點擊

我不能添加小提琴,因爲我沒有鏈接到Kendo UI庫,該列表正在使用。

<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> 

回答

3

你需要delegated event爲HTML DOM被加載後動態添加:

$(".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); 
     }); 
    }); 

在最後的下放事件的頁面詳見HERE

+0

我更新了我的代碼,但它仍然無效。我錯過了soemthign嗎? – Mark

+0

不,你沒有錯過任何東西,你可以提供一個jsfiddle嗎? –

+0

是'.k-state-focused'在頁面加載後也添加到了DOM? –