<div class="content" contenteditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
的JavaScript的这个代码是如何获得光标的行号段
var divheight = $(".content").height();
var lineheight = $(".content").css('line-height').replace("px","");
alert(Math.round(divheight/parseInt(lineheight)));
CSS是
.content {
line-height:20px;
}
例如,如果内部.content
的<span class="cursor"></span>
.cursor {
border-left: 1px solid black;
margin-left: -1px;
color: #2E3D48;
}
如何找到.cursor
是在矿井.content
刚刚试过样机小提琴的行数
https://jsfiddle.net/1ok3dah9/
如果是包装,技术上没有行号。所以我假设你正在寻找一个伪线号码? –
不清楚你的目标是什么。 –