首页  >  文章  >  web前端  >  Javascript selection的兼容性写法介绍_基础知识

Javascript selection的兼容性写法介绍_基础知识

WBOY
WBOY原创
2016-05-16 17:07:521441浏览
复制代码代码如下:

function getSelectedText() { //该函数代码借用自:http ://www.codetoad.com/javascript_get_selected_text.asp

var txt = "";
if (window.getSelection) {
txt = window.getSelection();
} else if (window.document.getSelection) {
txt = window.document.getSelection();
} else if (window.document.selection) {
txt = window.document.selection.createRange().text;
}
返回txt;
}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn