考虑以下内容可编辑div
.editable-div div {
display: inline-block;
}
<div contenteditable="true" class="editable-div">
<div> This </div> <div> is a an example</div><div> for inline block</div> <div>elemenst </div>
</div>
*选择为浏览器的文本选择(用户选择),我已经有用于选择div Selecting text in an element (akin to highlighting with your mouse)的整个内容的链接
但在这里我只想选择特定的文字。请帮忙
答案 0 :(得分:0)
我认为window.getSelection()
正是您所寻找的。 p>
var selection = "";
function getText() {
if (window.getSelection) {
selection = window.getSelection().toString();
} else if (document.selection && document.selection.type !== "Control") {
selection = document.selection.createRange().text;
}
return text;
}