1、获取选中的文字:

document.selection.createRange().text; IE9以下使用

window.getSelection().toString(); 其他浏览器使用

$('p').mouseup(function(){
    var txt = window.getSelection?window.getSelection():document.selection.createRange().text;
    alert(txt) ;
})

2、取消处于选中状态的文字:

document.selection.empty(); IE9以下使用

window.getSelection().removeAllRanges(); 其他浏览器使用

$('p').mouseup(function(){
    window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
})

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2022-02-26
  • 2021-11-07
  • 2021-10-12
  • 2022-02-11
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-09-24
  • 2022-02-04
  • 2022-01-02
相关资源
相似解决方案