html <2>标签怎么向右偏移,HTML - 如何获得与亲人选择偏移到HTML标签

我已经结束了正是如此解决它来处理所有情况:

var range = sel.getRangeAt(0);

// inserts two spans at the beginning and end of the range, to

// calculate the offsets

var div = document.createElement("span");

div.setAttribute("class", START_NODE);

range.insertNode(div);

range.collapse(false);

div = document.createElement("span");

div.setAttribute("class", END_NODE);

range.insertNode(div);

// gets the offsets by looking up the location of the inserted spans

// removes them after finding the offsets (also so the starting

// offset won't screw up the ending offset)

comment.startOffset = p.html().indexOf('');

$("." + START_NODE).remove();

comment.endOffset = p.html().indexOf('');

$("." + END_NODE).remove();

p.html(p.html());

基本上,我在范围选择开始时添加了一个SPAN,然后折叠范围并在其末尾添加一个SPAN。 然后我只搜索我添加的第一个跨度的索引,以及我添加的第二个跨度的索引以找到偏移量。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值