我有一个函数能够获取内容中选中的文本,但是我想要的是在该文本所属的HTML标签中加入一个唯一的ID。
function getSelectedText() {
if (window.getSelection) {
return window.getSelection();
} else if (document.selection) {
return document.selection.createRange().text;
}
return '';
}
$('#outline').on('click',function(){
var text = getSelectedText();
//here want to add the unique id to this paragraph that contains this text
});
我遇到了麻烦,找不到类似的解决方案。