jquery对话框 - 哪个按钮打开了对话框?

时间:2022-12-04 18:59:55

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!

在下面的示例中,如何使用事件和ui对象来检测打开对话框的链接?似乎无法获得$(event.target).attr(“title”);工作正常,我很难找到传递的'ui对象的文档。谢谢!

$("#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>

2 个解决方案

#1


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:

您需要在打开它的click事件中执行该检测,然后您可以使用它并在对话框中设置一些内容,提醒它...无论您要查看的值是什么,如下所示:

$("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


0  

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

parents()返回多个记录,而不是使用parent()。

#1


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:

您需要在打开它的click事件中执行该检测,然后您可以使用它并在对话框中设置一些内容,提醒它...无论您要查看的值是什么,如下所示:

$("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


0  

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

parents()返回多个记录,而不是使用parent()。