3

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?

4

2 回答 2

2

我有这个解决方案,请参见下面的示例。你有什么意见?

<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>
于 2014-11-27T13:27:10.603 回答
-1

答案是……你不能。

最接近的方法是双击文本,然后按住 Shift 并单击它。

于 2013-07-03T20:55:32.980 回答