2011-03-03 53 views
0

我有這樣的jQuery的功能:jQuery的 - 調用這個元素到另一個功能

$('a[name=pmRead]').click(function(e) { 
    e.preventDefault(); 

    $(this).parents(".pmMain").find(".pmMain5").toggle(); 

    $.ajax({ 
     type: 'POST', 
     cache: false, 
     url: 'pm/pm_ajax.php', 
     data: 'pm_id='+$(this).attr('id')+'&id=pm_read', 
     dataType: 'json', 
     success: function(data) { 
      $('#pmCouter').html(data[0]); 
      //HOW CAN I CALL THIS HERE? I'D like to do $(this).parents(".pmMain").find(".pmMain5").append('ciao'); 
     } 
    }); 
}); 

正如你可以在代碼中看到,我想回顧一下這個$就功能。我該怎麼做?

回答

4

只要將其存儲在一個變量,像這樣(把它命名爲錨):

$('a[name=pmRead]').click(function(e) { 
    e.preventDefault(); 

    var anchor = $(this); 

    anchor.parents(".pmMain").find(".pmMain5").toggle(); 

    $.ajax({ 
     type: 'POST', 
     cache: false, 
     url: 'pm/pm_ajax.php', 
     data: 'pm_id='+$(this).attr('id')+'&id=pm_read', 
     dataType: 'json', 
     success: function(data) { 
      $('#pmCouter').html(data[0]); 
      //HOW CAN I CALL THIS HERE? I'D like to do 
      anchor.parents(".pmMain").find(".pmMain5").append('ciao'); 
     } 
    }); 
}); 
+0

是的,謝謝! :) – markzzz 2011-03-03 15:39:02

0

你可以調用Ajax事件像

var thisObj = $(this); 

之前保存的對象和類的功能使用

thisObj.parents(".pmMain").find(".pmMain5").append('ciao'); 
相關問題