聘我网

新概念招聘3.0

如何用js抓获用户选择页面上文本的动作?

vote up0vote downstar

比如双击选定和拖动鼠标选定

 

1 个答复

vote up0vote downcheck

document.onmouseup来抓获事件,document.getSelection来获取选定内容

document.onmouseup = function() {
  var sel = document.getSelection();
  if (sel.length > 0) {
    alert(sel);
  }
}

这里有个demo

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.