答案 0 :(得分:1)
对于给定的问题,我有解决方案。
JavaScript本身提供了从文档中获取选定值的功能
通过使用window.getSelection();
或document.getSelection();
我尝试过的方法对我有用。
if (!window.x) {
x = {};
}
x.Selector = {};
x.Selector.getSelected = function() {
var t = '';
if (window.getSelection) {
t = window.getSelection();
} else if (document.getSelection) {
t = document.getSelection();
} else if (document.selection) {
t = document.selection.createRange().text;
}
return t;
}
$(document).ready(function() {
$(document).bind("mouseup", function() {
var mytext = x.Selector.getSelected();
alert(mytext);
});
});