日期:2014-05-17 浏览次数:20815 次
var oBtn = document.getElementById("button");
oBtn.onclick = function() {
var userSelection, text;
if (window.getSelection) {
//现代浏览器
userSelection = window.getSelection();
} else if (document.selection) {
//IE浏览器 考虑到Opera,应该放在后面
userSelection = document.selection.createRange();
}
if (!(text = userSelection.text)) {
text = userSelection;
}
alert(text);
};