【问题标题】:HTML select in textarea always select white space after doubleclick双击后文本区域中的 HTML 选择始终选择空白
【发布时间】:2013-07-01 17:24:08
【问题描述】:

当我在 textarea 中通过双击选择字符串(单词)时,总是在文本后选择单词和空格。

也许这是一个微不足道的问题,但是如何通过双击选择文本而不在单词后面留空格?

【问题讨论】:

    标签: html textarea double-click


    【解决方案1】:

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

    <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>
    

    【讨论】:

    • 在我的情况下(vue.js)whitesace 在双击后为&lt;1s 闪烁,但解决方案有效!非常感谢!
    【解决方案2】:

    答案是……你不能。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 2012-01-20
      相关资源
      最近更新 更多