我正在尝试将标签 
)插入contenteditable
td。我已经让它工作了一点,但它不会去我希望它去的地方(在光标上)。除非我在窗口中点击,否则它也会阻止我再次标记。
标签应在光标位置插入标签 
。我还应该能够继续制表并删除任何选择并将其替换为标签&esmp;
JSfiddle效果更好:https://jsfiddle.net/0qz8td9y/2/
function insertTab () {
if (event.which === 9)
{
event.preventDefault()
let selection = window.getSelection()
let text = selection.anchorNode.data
let start = selection.anchorOffset
let end = selection.focusOffset
let td = selection.anchorNode.parentNode
let remove = end - start
console.log(text + "hi")
console.log(selection)
text = text.split()
text.splice(start, remove, " ")
text = text.join("")
console.log(text)
td.innerHTML = text;
}
}
td {
border: 1px solid black;
width: 50px;
height: 50px;
}
<table>
<tr>
<td contenteditable="true" onkeydown="insertTab(event)">
</td>
</tr>
</table>