JS取得鼠标选择区域

   function getRangeById(id) {
            var word = '';
            if (document.selection) {

                  o = document.selection.createRange(); if (o.text.length > 0) word = o.text;

              }  else {
                o = document.getElementById(id); p1 = o.selectionStart; p2 = o.selectionEnd;
                if (p1 || p1 == '0') { if (p1 != p2) word = o.value.substring(p1, p2); }
            }
            return word;
        }

你可能感兴趣的:(JS取得鼠标选择区域)