2011-03-03 50 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'); 
相关问题