问题标签 [dom-selection]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - Jquery - 在新 div 中包装多个标签子类
我想使用 jQuery 将标签内的多个类包装到一个新的 div 中,这是 html 的例子:
结果 :
这是我尝试的 jQuery 代码:
我正在使用 jQuery wrap(); wrapAll();
,但我无法得到相同的结果。
javascript - document.getSelection 在选择中带有回车符
我尝试了很多不同的东西,但不知所措。下面的代码说明了这个问题。我有一个可编辑的元素。
如果我选择一段文本,则 Selection.anchorNode 是一个#text 节点。
如果在选择段落时我在该段落之前包含一个回车符,则 Selection.anchorNode 是包含 span 元素。
我需要知道的是从 span 元素的 innerText 值开始的偏移量是多少。When a carriage return IS NOT included in the selection, I am able simply to analyze the sibling nodes of the anchorNode. But when a carriage return IS included in the selection, I don't seem to have the information to achieve this.
任何关于我所缺少的指导将不胜感激。