我在 contenteditable div 中有一个跨度,我需要确定光标是否位于跨度标记的最后一个位置。我查看了选择和范围解决方案,但无法找到实现该目标的直接方法。
<html>
<script>
var selection = window.getSelection();
var range = selection.getRangeAt(0);
//this is what I am trying to achive
var selection_target = range.selectNodeContents(document.getElementById('target'));
var length = selection_target.toString().length;
</script>
<body>
<div id='target' contenteditable='true'>
<span>some text(figure cursor position here)</span>
</div>
</body>
</html>