2012-04-13 5 views
0

私は3はそれがすべてのリンクファイルの属性を置き換える必要がありJqueryの.load()関数が正常に起動しないのはなぜですか?

  1. のonloadステップ行うと仮定jqueryの関数を作った
  2. それは$に(「#内容を」)のサブページをロードする必要がありますクリック
  3. 再び、それはすべてのリンクに代わる機能をrefireする必要があり、再び

次のコードは、私はそれもロードされたページのリンクを交換するべきだと思い、再びすべてのURLを置き換える必要があり2つの段階が、doesntの火災第三段階まで動作しますか?

$(document).ready(function(){ 
    var base_url = "http://localhost/dolphin/"; 
    $("a").each(function(e){ 
    if(this.href == "javascript:void(0)" || 
     this.href == base_url || 
     this.href == base_url + "index.php" || 
     this.href == "javascript:void(0);" || 
     this.href == "javascript:%20void(0)") { 

    }else{ 
     page = 'Javascript:LoadPage(\''+ this.href + '\')'; 
     this.setAttribute('onclick',page); 
     this.setAttribute('href', '#'); 
    } 
    }); 
}); 

function LoadPage(url){ 
    $("#contentarea").load(url, function() { 
    //after loading it should call redoIt() but it doesnt. 
     redoIt(); 
    }); 
} 

function redoIt(){ 
    var base_url = "http://localhost/dolphin/"; 
    $("a").each(function(e){ 
     if(this.href == "javascript:void(0)" || 
      this.href == base_url + "index.php" || 
      this.href == "javascript:void(0);" || 
      this.href == "javascript:%20void(0)") { 

     }else{ 
     page = 'Javascript:LoadPage(\''+ this.href + '\')'; 
     this.setAttribute('onclick',page); 
     this.setAttribute('href', '#'); 
     } 
    }); 
} 
+0

はどのようにあなたが知っています正常に動作する必要があります 'redoIt()'と呼ば取得されていませんか?あなたはそれにブレークポイントを入れましたか?または最初に 'console.log()'ステートメント?エラーコンソールにJavaScriptエラーがありますか? 'LoadPage()'が呼び出されていますか? – jfriend00

+0

リンクを選択するあなたの方法は本当に恐ろしいです....長い間、jQueryのこのような恐ろしい誤用を見たことはありません。 – ThiefMaster

+0

redoIt()にアラート(this.href)を追加しましたが、返信はありませんでした – danny

答えて

1

$.loadへのあなたの呼び出しは、関数内で、私はあなたがどこでもそれが実行になっていないので、呼び出していない集めたものからです。それを取り出し、それが

$("#contentarea").load(url, function() { 

//after loading it should call redoIt() but it doesnt. 
redoIt(); 
}); 
関連する問題