【发布时间】:2023-03-16 08:01:01
【问题描述】:
这是我的代码,我在 div 中填充所有空间,(使用 jquery):
<div id="a" style="position:absolute;top:300px;width:100px;height:100px;background:red;color:black;word-wrap:break-word;">
<div id='a2' contenteditable=true ></div>
</div>
<script type="text/javascript">
String.prototype.repeat = function(n) {
return new Array(1 + parseInt(n, 10)).join(this);
}
var s=$('#a').width()/4*$('#a').height()/19;
$('#a2').html(' '.repeat($('#a').width()/4*parseInt($('#a').height()/19)))
$('#a2').click(function(){
alert('sss')
})
</script>
那么当我单击“a2”div 中的某个位置时,如何获取文本光标位置
谢谢
【问题讨论】:
-
什么光标,文本还是鼠标?
-
@Pekka Mouse - 演示只是一个红框。
-
@Šime 是真的,但它包含一个带有
contenteditable=true的div。 -
对不起,我想获取文本光标,
-
获得插入符号位置后,您想做什么?
标签: javascript cursor position