2016-09-27 90 views
0

我有一个侧栏,其中有一个链接到帐户页面。现在点击该侧边栏中的帐户,关于JavaScript没有执行,如果我重新加载页面,它正在正确执行。我无法理解这种行为。谁能帮我理解这个问题页面加载点击链接,不起作用

$(document).on("ready page:load",function(){ 

    makeProfile(); 

}); 




function makeProfile(){ 

     $('#profile-form').hide(); 

     $('.profile-edit').on("click",function(e){ 


      // if they click on edit, show the form, other wise show the divs 
      if($('.profile-edit').text() == "Edit"){ 
      $('.profile-edit').text("Save"); 
      $('.profile-details').hide(); 
      $('#profile-form').show(); 
      }else{ 

       $('.submit-hidden').click(); 

      } 

     }); 
} 
+0

我们可以看到,它试图与工作中的HTML?如果你切换到'$(document).ready(function(){ makeProfile(); });' 这样你就可以使用jQuerys文档而不是'on'监听器。 – dj10dj100

+0

实际上,如果我们重新加载页面,那意味着就绪在那个时候执行正常。但问题是与涡轮链接 – gates

回答

0

尝试turbolinks:load

$(document).on("turbolinks:load",function(){ 

    makeProfile(); 

}); 
相关问题