0
我在contenteditable div內有一個span,我需要弄清楚光標是否位於span標籤的最後一個位置。我查看了選擇和範圍解決方案,但無法找出實現這一目標的簡單方法。在元素內部查找插入符號位置
<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>