<body>
<input type="text" id="test" value="ajanuw">
<script>
document.querySelector('#test').addEventListener('mouseup', (e)=>{
var activeElement = document.activeElement;
console.log( activeElement.selectionStart, activeElement.selectionEnd);
var start = activeElement.selectionStart,
end = activeElement.selectionEnd;
console.log( e.target.value.substring(start, end));
}, false)
</script>
</body>
转载于:https://www.cnblogs.com/ajanuw/p/8005871.html