【问题标题】:jquery dialog - which button opened the dialog?jquery 对话框 - 哪个按钮打开了对话框?
【发布时间】:2010-04-11 20:46:43
【问题描述】:

在下面的示例中,如何使用 event 和 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>

【问题讨论】:

  • 谁能弄清楚如何正确使用与对话框相关的“事件”和“用户界面”对象?

标签: jquery jquery-ui event-handling jquery-ui-dialog


【解决方案1】:

您需要在打开它的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 :)
});

【讨论】:

  • 天哪,我只是认为 JQuery 会有一种更漂亮的方式来传递变量。猜猜这将不得不做。感谢您的帮助!
【解决方案2】:

parents() 返回多条记录使用 parent() 代替。

【讨论】:

  • 我只是将帖子中的代码简化为只是尝试获取按钮的标题,只是进行了测试,我什至无法获取按钮的标题...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多