如何自动关闭括号[]和自动关闭大括号{}?我尝试过使用@Ivan Ganchev 的想法:
maintextarea.addEventListener('keyup', function (ev) {
let position = this.selectionStart;
if (ev.keyCode == 222) { // I replaced this with 219 for open bracket and curly bracket
let value = ev.target.value;
ev.target.value = [value.slice(0, position), ev.key, value.slice(position)].join('');
ev.target.selectionEnd = position;
}
});
但结果是这样的: {{ 或: [[。
郎朗坤
相关分类