jquery dialog - which button opened the dialog?

痞子三分冷 提交于 2020-01-05 08:08:35

问题


In the example below, how can you use the event and ui objects to detect which link opened the dialog? Can't seem to get $(event.target).attr("title"); to work properly, and I'm having trouble finding documentation on the 'ui object that is passed. Thanks!

$("#dialog_support_option_form").dialog({
   link_title = $(event.target).attr("title");
   alert(link_title);
});


$("a").live("click", function() {
    btn_rel = $(this).attr("rel");
    $(btn_rel).dialog("open");
});

<a class="btn pencil" rel="#dialog_support_option_form" title="Edit Support Option">Edit</button>

回答1:


You need to do that detection in the click event that opens it, you can then use it and set something in the dialog, alert it...whatever you're looking to do with the value, like this:

$("a").live("click", function() {
  var btn_rel = $(this).attr("rel");
  $(btn_rel).dialog("open");
  var title = $(this).attr("title");
  //alert(title);
  //or:
  //$("#dialog_support_option_form .something").text(title);
  //whatever you want to do with it :)
});



回答2:


parents() returns multiple records use parent() instead.



来源:https://stackoverflow.com/questions/2601594/jquery-dialog-which-button-opened-the-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!