2011-03-06 54 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.log顯示15

例如,當我使用alert包裝execCommand(第二個,它在頁面加載後調用)時,它返回false。

有什麼問題嗎?爲什麼頁面加載後返回錯誤?謝謝。

回答

1

看起來像$(document).ready(...)在EditArea實例完成初始化之前觸發。當您觸發#line_go上的點擊事件時,它是在EditArea實例初始化之後,因此能夠檢索關於它的信息或對其執行操作。

+0

是的,你是對的,謝謝。 – Ockonal 2011-03-06 11:41:07