使用 JQuery Click() 时无法传递事件

Cannot Pass event When Using JQuery Click()

我在使用下面的点击功能时无法从event.data获取数据。如果我将 "event" 放在 click(smedata, function(event){}) 中,它不会触发。如果我删除事件,它就会触发。过去我已经这样做了一百次,但无论出于何种原因,这次都行不通。我能想到的是,这段代码是在关闭对话 window 的回调期间生成的,这在某种程度上是干扰。感谢任何帮助。

//This is a callback function in a library that gets called after a dialogue 
//window from SharePoint SP.UI.Dialogue gets closed.

OESme.prototype.CloseCallback = function(result, target){
  console.log("callback");

  try{
    var targetArray = target.split(";#");
  }
  catch(e){

  }
  
  //object to be passed to click event
  var smedata = {
    smejson: target,
    id: targetArray[0],
    title: targetArray[1],
    rank: targetArray[2],
    firstname: targetArray[3],
    lastname: targetArray[4]
  }

  var smeID = "smedata" + smedata.id;
  var smeIDJQ = "#" + "smedata" + smedata.id;

  $("#SMEAddedBox").append(
    '<div class="smeitem">' + 
      '<span id="' + smeID + '">x</span>' + smedata.title + 
    '</div>'
  );


   //*******************   
  //When clicking the x it is suppose to remove itself
  //If event is a parameter in the function, it won't fire, if event is removed it fires, but I can't use the object I am trying to pass
  //********************

  $(smeIDJQ).click(smedata, function(event){
      console.log(event.data);
      $(this).parent().remove();

  });
           
}

您似乎没有正确引用 $(smeIDJQ)。另外,请改用 .on。喜欢$('#smeIDJQ').on('click', function(){};

我的所有代码都是正确的。该问题与 SharePoint SP.UI.Dialogue.js 有关。所有 javascript 和 jQuery 都是正确的,但在对话 window 中是 运行。基本上一页上有两个单独的页面运行。当对话 window 在回调后关闭时,Internet Explorer 11 中的控制台中断并且没有意识到应该关注父页面而不是子页面。所以它不会像它应该的那样接收控制台日志。关闭开发人员工具并重新打开 (F12) 允许 window 正确地重新聚焦父对象。