2013-07-28 218 views
0

我想有權通過$ .ajax()發送我的信息時(當時)我點擊更新按鈕,但我無法處理更新按鈕點擊事件。爲什麼使用jquery。 On()不適用於動態元素?

我想要的代碼來處理更新按鈕點擊事件,但我沒有工作

jsfiddle code

代碼:

$(".table").on("click", "k-grid-update", (function() { 

     alert('xxx'); 

     //$.ajax({ 

     // url: 'api/apdevice', 
     // type: 'PUT', 
     // datatype: 'application/json', 
     // data: {}, 
     // success: function (data) { 

     // }, 

     // error: function (data) { 

     // } 

     //}); 

謝謝

+0

也許你正在使用的不支持'。對()'jQuery的版本? –

回答

1

這不是它不工作:問題是KendoUI重新定義了同一個元素的動作。

你不應該直接將它綁定到按鈕,而是使用一些KendoUI提供的機制來完成它。您可以在Kendo Grid中使用save事件,也可以在DataSource.transport上定義方便的update功能。

例子:

$('.table').kendoGrid({ 
    dataSource : { 
     transport: { 
      read : function (op) { 
       op.success(data) 
      }, 
      update: function (op) { 
       alert("xxx - update"); 
       ... 
      } 
     }, 
     schema : { 
      model: { 
       id: "Mac" 
      } 
     } 
    }, 
    sortable : true, 
    groupable : true, 
    selectable : true, 
    navigatable: true, 
    height  : 500, 
    scrollable : true, 
    pageable : true, 

    rowTemplate : kendo.template($("#client-row-template").html().replace('class="k-alt"', '')), 
    altRowTemplate: kendo.template($("#client-row-template").html()),//@class="k-alt"@ 
    editable  : "popup", 
    save   : function (a) { 
     alert("xxx - save"); 
     ... 
    } 

}); 
1
$(".table").on("click", "k-grid-update", 

有你的問題。您很可能希望爲代表的一類選擇,因爲沒有名爲k-grid-update HTML標籤存在:

$(".table").on("click", ".k-grid-update", 
+1

而'('之前的函數應該被刪除。 – ZippyV

+3

@ZippyV:是的,但它並不重要,因爲他也有''''。 'foo'和'(foo)'通常是一樣的。 – ThiefMaster

相關問題