When I select string (word) by doubleclick in textarea, then always select word and white space after text.
Maybe it's trivial question, but how to select text by doubleclick without white space after word?
When I select string (word) by doubleclick in textarea, then always select word and white space after text.
Maybe it's trivial question, but how to select text by doubleclick without white space after word?
我有这个解决方案,请参见下面的示例。你有什么意见?
<html>
<body>
<textarea cols=50 ondblclick="checkDblClick(event)">abc1space abc2space abc3space abc
</textarea>
<script>
function checkDblClickDelayed(target) {
while (target.value.substr(target.selectionEnd -1, 1) == " ") {
target.selectionEnd = target.selectionEnd - 1;
}
}
function checkDblClick(e) {
//we make a delay of 0ms to wait until the selection is in the final position
target = e.target;
setTimeout(function()
{
checkDblClickDelayed(target);
}
, 0);
}
</script>
</body>
</html>
答案是……你不能。
最接近的方法是双击文本,然后按住 Shift 并单击它。