• js document.activeElement 获得焦点的元素


    <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>
    
    
  • 相关阅读:
    8月10日
    8月9日
    8月8日
    8月7日
    8月6日
    8月5日
    《大道至简》读后感
    8月4日
    8月3日
    8月2日
  • 原文地址:https://www.cnblogs.com/ajanuw/p/8005871.html
Copyright © 2020-2023  润新知