[英]Get the html (source code) index of a selection?
如果我有
<div>
hello
</div>
我用光标选择'hello',起始索引为6,结束为11(含)。
有没有办法通过JavaScript或jQuery跨浏览器获取此信息?
如果你有jQuery,你可以这样做:
var selectionText = $(window.getSelection().getRangeAt(0).cloneContents()).text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.