2013-10-24 2 views
0

나는이 사이드의 JQuery UI 아코디언을 가지고있다. 나는 섹션의 클릭 이벤트에 대한 추가 작업을 할 내가있어이 this SO와 반응에 따라 작업 : 작동 이제터보 링크와 아코디언이있는 레일

$(".sidebar_category").click(function(event) { 
    // the section contains a span and my anchor; only go when 
    // the click is over the anchor 
    if (event.target.href !== undefined) { 
    window.location = event.target.href; 
    } 
}); 

...하지만 다른 링크에 같은 방식으로 클릭 왜냐하면 터보 링크를 사용함으로써 AJAX switcheroo가 수행되어서 에뮬레이트하고 싶기 때문입니다.

바늘은 simulating a click이 트릭을하지 않는다고 말합니다. 나는 this :

<html> 
    <head> 
    <script type="text/javascript" src="jquery-1.3.1.js"></script> 
    <script type="text/javascript" src="jquery.form.js"></script> 
    <script> 
     $(document).ready(function(){ 
      $('a').bind('click',function(event){ 
      event.preventDefault(); 
      $.get(this.href,{},function(response){ 
       $('#response').html(response) 
      }) 
     }) 
     }); 
    </script> 
    </head> 
<body> 
    <li><a href="response.html"/>Response</a> 
    <div id="response"></div> 
</body> 

그러나 레일 스타일과 같은 것을 기대하고 있습니다. 그러면 링크 터보 링크 스타일을 어떻게 따릅니 까?

PS : 내 제거 gemfile :

gem 'rails', '4.0.0' 
gem 'sqlite3' 
gem 'sass-rails', '~> 4.0.0' 
gem 'uglifier', '>= 1.3.0' 
gem 'coffee-rails', '~> 4.0.0' 
gem 'jquery-rails' 
gem 'jquery-ui-sass-rails' 
gem 'jquery-ui-themes' 
gem 'turbolinks' 
... 

답변

1

Turbolinks는 우리의 응용 프로그램을 대신 전체 페이지로드에 의존 새로운 페이지의 HTML 본문을 대체하기 위해 자바 스크립트를 사용하여 빠르게 사용자에게 표시하기 위해 사용하고 있습니다. 헤드 태그 안의 코드는 모든 페이지에서로드되지 않습니다. 따라서 몸 안쪽에 태그를 넣으십시오.

<script> 
     $(document).ready(function(){ 
      $('a').bind('click',function(event){ 
      event.preventDefault(); 
      $.get(this.href,{},function(response){ 
       $('#response').html(response) 
      }) 
     }) 
     }); 
    </script> 
+0

네, 고맙습니다. 나는 "레일 스타일"에 대해 물어 보았습니다. 아마도 일종의 방법이었을 것입니다. –

관련 문제