简体   繁体   English

使用jQueryUI Dialog,我如何获得打开对话框的元素?

[英]Using jQueryUI Dialog, how can I get the element that opened the dialog?

For example, I have many rows of data, each with an "edit" button with a class "edit-button". 例如,我有许多行数据,每行都有一个带有“编辑按钮”类的“编辑”按钮。

I have a .live() click handler on for .edit-button elements. 我对.edit-button元素有一个.live()单击处理程序。

In a dialog callback for one of the "buttons", I would like to pass the row as an argument. 在其中一个“按钮”的对话框回调中,我想将该行作为参数传递。

Specifically, I'd like to get the ID attribute of the .edit-button 's parent tr (in a table). 具体来说,我.edit-button的父tr (在表中)的ID属性。

Usually, I might do something along the lines of: 通常,我可能会做以下事情:

var tr = $(element).parents("tr:first");

...to get the tr element. ...获取tr元素。

How would this be achieved? 这将如何实现?

When binding with .live('click', function(eventObj) .live('click', function(eventObj)绑定时.live('click', function(eventObj)

eventObj will give you access to the eventObj.target that you can use to determine which DOM element fired it. eventObj将允许您访问eventObj.target,您可以使用它来确定触发它的DOM元素。

References: 参考文献:

* the example relates to using event to get .type, but you can also get .target from it. *该示例涉及使用event来获取.type,但您也可以从中获取.target。

Store the element ( this in the click handler) somewhere so you can access it later. 存储单元( this单击处理程序)的地方,以便以后可以访问它。 If you want the parent TR, use var tr = $(this).closest('tr'); 如果你想要父TR,使用var tr = $(this).closest('tr');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM