获取选中的文本

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <div>Hello, World!</div>
    <script>
      window.onmouseup = function () {
        const selectText = window.getSelection().toString();
        if (selectText) {
          alert(selectText);
        }
      };
    </script>
  </body>
</html>

posted on 2021-09-10 09:55  aisowe  阅读(18)  评论(0编辑  收藏  举报

导航