0

이것은 HTML의 구조입니다. 사용자가 className "next_button"을 사용하여 div를 클릭하면 이벤트 리스너를 추가해야합니다. 프로토 타입을 사용하여 이벤트 리스너를 추가하려고합니다.요소에 이벤트 리스너 등록에 대한 도움말

<div id="horizontal_carousel2"> 
    <div class="previous_button"></div> 
    <div class="container" > 
    <ul> 
     <li></li> 
     <li></li> 
     <li></li> 
     <li></li> 

    </ul> 
    <div id="spinner2" style="display: block;"><br /></div> 
    </div> 
    <div class="next_button"></div> 
</div> 

This is the script which executes on load. 

<script type="text/javascript"> 
Event.observe(window, 'load', function() { 
      $$("#horizontal_carousel .next_button").first().observe('click',tezt()); 

}); 

function tezt() 
{ 
    alert("calling me"); 
} 
</script> 


The problem is "calling me" alerted as the window load completes. I am not able to figure out the problem. What i missing. I have to show alert message when user click on next button.. Thank You 
+2

'.observe ('click', tezt)'시도 (즉, tezt 이후에'()'를 제거하십시오). –

+0

그것은 작동합니다. 신선한 씨 감사합니다. – Shashi

+0

제발, Crescent라고 불러주세요. 또한, 오신 것을 환영합니다. 내가 왜 다른 사람들에게 설명하여 * 왜 * 효과가 있었는지 설명하겠습니다. –

답변

1

관찰 할 두 번째 매개 변수는 함수에 대한 참조 여야합니다. 두 번째 매개 변수로 tezt()를 전달하면 tezt()를 실행하고 결과는입니다.