link_to_remote 에서 자바스크립트를 사용하기.

link_to_remote 를 가지고 잘 사용하면 매우 좋겠지만.

 

http://www.intridea.com/2007/11/21/link_to_remote-unobtrusively 

 

위의 링크를 따라가면 해당 방법을 볼 수 있긴 한데..

 

저 방법보단 간단하게 풀어보면.

 

<a href="#" onclick='link1()'>Home</a>

 

<script>
    function link1()
    {
        $('nav1').className='active';
        $('nav2').className='';       
        $('nav3').className='';       
        $('nav4').className='';           
        new Ajax.Updater('contents', '/milestones', {asynchronous:true, evalScripts:true});   
    }

</script>

 

위와 같은 방법으로도 할 수 있다.

 

즉, link_to_remote 헬퍼 함수를 html 로 쉽게 풀어서 사용한 것이다.

 

차라리 저게 더 쉽고 간단할지도.

 

위에 보면 Prototype 에서 $ 약자는 getElementById 의 축약형이다. 위의 구문의 className 메쏘드는

클래스를 바꿔주는것이다. CSS 의 네비 바에서 사용될 수 있다.