问题
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