如何告诉jQuery:当负载准备就绪时,显示这个?

时间:2009-09-02 12:37:58

标签: jquery dom adjustment

此代码:

$("#permalink a").click(function(id){
var id = this.getAttribute('href');
$("#newPostContent").load(id, function() {
 $("#removeTrigger").click(function() {
 $("#removeThis").hideToggle();
 $("#postSingle").hideToggle();
 });
});
   $("#postSingle").fadeToggle();
   return false;
});

在加载功能完成其工作之前显示#postSingle。我该如何调整呢?

谢谢

(今天很多问题,谢谢大家:))。

2 个答案:

答案 0 :(得分:2)

在回调函数中 load后,将您想要发生的所有事情发生:

$("#permalink a").click(function(id){
    var id = this.getAttribute('href');
    $("#newPostContent").load(id, function() {
        $("#removeTrigger").click(function() {
             $("#removeThis").hideToggle();
             $("#postSingle").hideToggle();
        });
        $("#postSingle").fadeToggle();
    });
    return false;
});

答案 1 :(得分:-1)

您是否尝试将其包装在文档就绪块中?像:

$(document).ready(function() {
  $("#permalink a").click(function(id){
  var id = this.getAttribute('href');
  $("#newPostContent").load(id, function() {
   $("#removeTrigger").click(function() {
   $("#removeThis").hideToggle();
   $("#postSingle").hideToggle();
   });
  });
   $("#postSingle").fadeToggle();
   return false;
});
});