Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择嵌套在contenteditable中的整个元素,即使只选择了其中的一部分_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 选择嵌套在contenteditable中的整个元素,即使只选择了其中的一部分

Javascript 选择嵌套在contenteditable中的整个元素,即使只选择了其中的一部分,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个contenteditable div,其中嵌套了一些span标记。我要做的事情是选择整个元素,即使只有一个部分被选中,它应该与点击鼠标和拖动以及按住shift+导航键一起工作。 布局可能如下所示: <div contenteditable="true" id="text"> Some text goes here <span class="highlight">Some tag in here</span> Some m

我有一个contenteditable div,其中嵌套了一些span标记。我要做的事情是选择整个元素,即使只有一个部分被选中,它应该与点击鼠标和拖动以及按住shift+导航键一起工作。 布局可能如下所示:

<div contenteditable="true" id="text">
     Some text goes here
     <span class="highlight">Some tag in here</span>
     Some more text
     <span class="highlight">More tagged text</span>
</div>
我想做的是在文本中添加一个不可编辑的标记,但你仍然可以将它们与文本的其余部分一起复制


提前感谢。

您是否尝试将contenteditable=false添加到s-一般来说,我认为您要做的是基于浏览器的document.getSelection或window.getSelection来获取页面上的选择。接下来,迭代每个选定节点的父节点,直到在所有选定节点中找到一个公共父节点。如果我理解正确,您还需要确保公共父节点的nodeType=1。