最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CodeMirror onBlur event and console.log() - Stack Overflow

programmeradmin7浏览0评论

From what I've read about CodeMirror I should have onBlur written to my Console Log when I Blur the textarea. Nothing gets echo'd.

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

Have I missed anything out at all?

From what I've read about CodeMirror I should have onBlur written to my Console Log when I Blur the textarea. Nothing gets echo'd.

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

Have I missed anything out at all?

Share Improve this question edited Feb 9, 2018 at 14:22 Alexander 23.5k11 gold badges64 silver badges73 bronze badges asked Feb 26, 2013 at 16:24 ngplaygroundngplayground 21.6k37 gold badges98 silver badges174 bronze badges 1
  • 1 For anyone surfing Stack Overflow for answers on legacy builds, the onBlur function within the CodeMirror instance shown above is the correct method for older versions of CodeMirror. Newer versions use editor.on(). – Gagich Commented Feb 4, 2019 at 13:43
Add a ment  | 

1 Answer 1

Reset to default 17

Bind it using .on() as described in 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)

  1. 暂无评论