zjhax

document.getElementById(\'btnselecttext\').onclick = function () {
var content = getSelectText2(\'content\');
document.getElementById(\'show\').innerHTML = content;
}

 

function getSelectText2(id) {
var t = document.getElementById(id);
if (window.getSelection) {
if (t.selectionStart != undefined && t.selectionEnd != undefined) {
if (t.selectionEnd == 0 || t.selectionStart >= t.selectionEnd) {
BM.alert("未选中文字");
return "";
}
var str = t.selectionStart + 1 + "," + t.selectionEnd;
$("#sepositon").val(str);
var textContent = t.value.substring(t.selectionStart, t.selectionEnd);

return "选中文本:" + textContent + ",起始位置:" + (t.selectionStart + 1) + " ,结束位置:" + t.selectionEnd + "";
} else {
BM.alert("未选中文字");
return "";
}
} else {
return document.selection.createRange().text;
}
}

 

分类:

技术点:

相关文章: