[英]CodeMirror using jQuery .keyup on editor textarea
I want to getValue of Codemirror editor on keyup but it did not work. 我想在keyup上获取Codemirror编辑器的Value,但是没有用。 Here's the fiddle
这是小提琴
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor = CodeMirror.fromTextArea(document.getElementById("HTML"), {mode: mixedMode,lineNumbers: true });
$(document).ready(function(){
$("#HTML").keyup(function(){
html = editor.getValue();
alert(html);
});
});
CodeMirror hides the textarea
element, for listening to the events of the editor instance you can use the on
method: CodeMirror隐藏了
textarea
元素,可以使用on
方法来监听编辑器实例的事件:
$(document).ready(function () {
editor.on('change', function () {
html = editor.getValue();
alert(html);
});
});
You can find the list of the supported events in the CodeMirror's manual. 您可以在CodeMirror的手册中找到受支持事件的列表。
http://codemirror.net/doc/manual.html#events http://codemirror.net/doc/manual.html#events
editor.on("keyup", function(cm, event) {
//only show hits for alpha characters
if(!editor.state.completionActive && (event.keyCode > 65 && event.keyCode < 92)) {
if(timeout) clearTimeout(timeout);
var timeout = setTimeout(function() {
CodeMirror.showHint(cm, CodeMirror.hint.clike, {completeSingle: false});
}, 150);
}
});
Replace 'CodeMirror.hint.clilke' with whichever hint mode you are using :) 用您正在使用的任何提示模式替换'CodeMirror.hint.clilke':)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.