您的位置:首页 > 其它

div contenteditable光标位置问题

2014-12-15 17:48 645 查看
<span style="color:#ff0000;">插入数据后,光标位置问题</span>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div contenteditable光标测试</title>
<style type="text/css">
.div{ width:600px; height:200px; border:1px solid #CCC}
</style>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$('.aclick').click(function(){
$('.div-label').html("回复[潇sdfsdfssssssssssssssdfsdf潇]:");
$('.div').focus();
getC($('.div'))
})
});
function getC(that){
if(document.all){
that.range=document.selection.createRange();
that.range.select();
that.range.moveStart("character",-1);
}else{
that.range=window.getSelection().getRangeAt(0);
that.range.setStart(that.range.startContainer,2);
}
}
</script>
</head>

<body>
<a href="#" class="aclick">回复潇潇</a>
<div class="div" contenteditable="true">
<label contenteditable="false" class="div-label">回复标题:</label>
</div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: