目标: 我使用codemirror作为编辑器。我想要
问题:
JSFIDDLE: https ://jsfiddle.net/bababalcksheep/p7xg1utn/30/
代码:
$(document).ready(function() {
//
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: "text/html",
lineNumbers: true,
});
//
function search(val) {
var cursor = editor.getSearchCursor(val);
while (cursor.findNext()) {
editor.setSelection(cursor.from(), cursor.to());
console.log('found at line ', cursor.pos.from.line + 1);
}
}
//
$('#search').click(function(event) {
event.preventDefault();
search(/^alpha|^beta/);
});
//
});
Run Code Online (Sandbox Code Playgroud)