将图标添加到我的编辑窗体中

问题描述:

我正在尝试将图标添加到我的编辑窗体中。该图标按预期显示,但不会对点击事件做出反应。将图标添加到我的编辑窗体中

使用免费的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); 
}); 

是错误的使用$('.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

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