2016-10-19 46 views
0

我正在嘗試將圖標添加到我的編輯窗體中。該圖標按預期顯示,但不會對點擊事件做出反應。將圖標添加到我的編輯窗體中

使用免費的jqGrid 4.13

colModel

{name:'characteristic', index:'characteristic', width:150, editable: true, 
    editoptions:{rows:'3',cols:'50'}, editrules:{edithidden:true}, 
    formoptions:{rowpos:3, colpos:1,label:"Characteristic:", 
    elmsuffix: " <img class='genericnotes' src='/QMSWebApp/Images/addnote[3].jpg'>"}, 
    edittype:'textarea'}, 

在loadComplete:

$('.genericnotes').on("click", function(){ 
    var tControl = this.name; 
    alert(tControl); 

    //$('.miscdisplay').load("/QMSWebApp/FirstArticleControllerServlet", 
    //{lifecycle:"faieditlistdisplay", 
    //tControl:tControl, 
    //source:0}); 
    //$('.miscdisplay').show("slide", { direction: "right" }, 1000); 
}); 

回答

1

是錯誤的使用$('.genericnotes').on("click", function(){...});loadComplete內,因爲編輯表單目前不存在。您應該使用例如beforeShowForm表單編輯回調。免費jqGrid允許指定jqGrid的formEditing選項中的表單編輯選項/回調(請參閱the wiki article)。因此,你可以通過

formEditing: { 
    beforeShowForm: function() { 
     $("#characteristic") // select textarea#characteristic 
      .next(".genericnotes") 
      .on("click", function() { 
       alert("Click"); 
      }); 
    } 
} 
+0

@ OlegThanks,偉大的作品。 –

+0

@SteveDyke:不客氣! – Oleg

0

嘗試var tControl = $(this).attr("name");

+0

使用情況沒有工作click手柄結合img.genericnotes,但我不認爲這是問題的根源。它的作用就像點擊事件沒有被綁定到loadComplete方法中的圖標。 –

+1

雖然此代碼片段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – andreas

+0

Okidok,將嘗試:) – Jan

相關問題