2011-03-06 1 views
0

저는 EditArea 편집기를 사용하고 있습니다. 함수가 있습니다 : editAreaLoader.execCommand, 그것은 인자를 가진 인자와 명령의 id를받습니다. 그래서 코드 :함수 호출시 문제가 발생했습니다

$(document).ready(function() { 
    // Call go to line function after click at button 
    $('#line_go').click(function() { 
     console.log($('#line_to').val()); 
     editAreaLoader.execCommand('example_1', 'go_to_line', $('#line_to').val()); 
    }); 

    // Try to do the same but after loading of the page 
    editAreaLoader.execCommand('example_1', 'go_to_line',$('#line_to').val()); 
}); 

HTML :

<input type="edit" name="line" id="line_to" value="15" /> 
<input type="button" name="line_go" id="line_go" value="Go" /> 

그래서, 페이지가로드의 아무 반응이 없을 때. 하지만 버튼 편집기를 클릭하면 # 15 행으로 바뀝니다. console.log15입니다.

예를 들어, execCommand (두 번째로 페이지 로딩 후라고 함)을 경고와 함께 래핑하면 false를 반환합니다.

무엇이 잘못 되었습니까? 페이지 로딩 후 호출이 false를 반환하는 이유는 무엇입니까? 감사.

답변

1

EditArea 인스턴스가 자체 초기화를 완료하기 전에 $(document).ready(...)이 발생합니다. #line_go에서 click 이벤트를 발생 시키면 EditArea 인스턴스가 초기화 된 후이므로 해당 이벤트에 대한 정보를 검색하거나 그에 대한 작업을 수행 할 수 있습니다.

+0

네, 맞습니다. 고마워요. – Ockonal