I have couple of input fields with the class "link". All of them should start the jqueryUI dialog so this is why I bind the method to a class and not an single id. The difficulty is now that i can't use the (this) in line 12, because that gives me the identity of the dialog and not the input element.
As I am an beginner I don't know how to pass a variable to this event with the element of the input field.
What I want to archive is that the dialog should start from the input field and should write the result back to that input field.
1. // this is the click event for the input-field class called "link"
2. $('.link')
3. .button()
4. .click(function() {
5. $('#dialog-form').dialog('open');
6.
7. });
8.
9. //this is an excerpt from the opened dialog box and the write back to the input field
10. $("#dialog-form").dialog({
11. if (bValid) {
12. $('.link').val('' +
14. name.val() + '');
15. 开发者_Go百科 $(this).dialog('close');
16. }
17. });
$('.link').button().click(function() {
$('#dialog-form').data('clicked', $(this)).dialog('open');
});
$('#dialog-form').dialog({
if (bValid) {
$('#dialog-form').data('clicked').val(name.val());
$(this).dialog('close');
}
});
$('.link').button().click(function() {
$(this).addClass("selected-link");
$('#dialog-form').dialog('open');
});
$("#dialog-form").dialog({
if (bValid) {
$('.link.selected-link').val('' + name.val() + '');
$(this).dialog('close');
}
});
the $('.link').something()
, binds the event something to every DOM node with the class "link". You are mistaken on what you said. You can still use the $(this)
as it refers to the activated DOM node and not the collection of classes that the event was associated to.
精彩评论