内容可编辑,在文本末尾设置插入符号(跨浏览器)
<div id="content" contenteditable="true" style="border:1px solid #000;width:500px;height:40px;"> hey <div>what's up?</div><div><button id="insert_caret"></button>
hey<br />what's up?
hey<p>what's up?</p>
<br />
hey what's up?|
$(document).ready(function(){ $('#insert_caret').click(function() { var ele = $('#content'); var length = ele.html().length; ele.focus(); //set caret -> end pos } }