当用户在页面上选择一些文本时触发了什么事件? [英] What's the event fired when user selects some text on the page?

查看:123
本文介绍了当用户在页面上选择一些文本时触发了什么事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双击或移动鼠标。

有人知道吗?

推荐答案

也许您可以将函数绑定到 document.onmouseup document.getSelection()?这是假设您的用户使用鼠标选择文本;)

Maybe you can bind a function to document.onmouseup to call document.getSelection()? This is assuming your users use mouse to select the text ;)

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

这篇关于当用户在页面上选择一些文本时触发了什么事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆