这是我的代码,我用jQuery填充了div中的所有空白:
<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中的某个位置单击时,如何获取文本光标位置?
演示链接:http://jsfiddle.net/KBnKc/
谢谢。
contenteditable=true
的 div。 - Pekka