2013-02-26 241 views
8

從我讀過的有關CodeMirror的內容中,我應該將onBlur寫入我的控制檯日誌中,當我模糊textarea時。什麼都沒有得到迴應。CodeMirror onBlur事件和console.log()

var textarea = document.getElementById('block'); 
var editor = CodeMirror.fromTextArea(textarea, { 
    lineNumbers: false, 
    content: textarea.value, 
    onBlur: function() { 
     console.log("onBlur"); 
    } 
}); 

我錯過了什麼嗎?

回答

12

使用.on()將其綁定,如the CodeMirror's Events documentation中所述。

var textarea = document.getElementById('block'); 
var editor = CodeMirror.fromTextArea(textarea, { 
    lineNumbers: false, 
    content: textarea.value, 
}); 
editor.on("blur", function(){ 
    console.log("onBlur"); 
}); 
+0

謝謝,我在這裏找到https://github.com/marijnh/CodeMirror/issues/818太 – ngplayground 2013-02-26 16:31:25

+1

@DonaldSutherland,太好了。我閱讀文檔 – Alexander 2013-02-26 16:33:36