为什么Jquery .load()函数没有成功触发?

时间:2012-04-13 14:59:45

标签: jquery hyperlink href

我做了一个jquery函数,假设做了3个步骤

  1. onload它应该替换所有链接文件的属性
  2. 点击它时应将子页面加载到$(“#content”)
  3. 它应该重新启用将再次替换所有链接的功能
  4. 以下代码一直工作到2个步骤但是没有触发第三步,它应该再次替换所有网址我认为它应该替换加载页面的链接?

    $(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', '#');
           }
       });
     }
    

1 个答案:

答案 0 :(得分:1)

你对$.load的调用是在一个函数内部,而且从我收集的内容中你并没有在任何地方调用它,因此它没有被执行。拿出来它应该可以正常工作

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

//after loading it should call redoIt() but it doesnt.
 redoIt();
});
相关问题