內(nèi)容可編輯,在文本末尾設(shè)置插入符號(hào)(跨瀏覽器)輸出鉻:<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>我相信法夫它看起來(lái)會(huì)是這樣的:hey<br />what's up?和在伊:hey<p>what's up?</p>不幸的是,沒(méi)有很好的方法使每個(gè)瀏覽器都插入一個(gè)<br />而不是一個(gè)div或者p標(biāo)簽,或者至少我在網(wǎng)上找不到任何東西。不管怎樣,我現(xiàn)在想做的是,當(dāng)我擊中扣子,我希望將插入符號(hào)設(shè)置在文本的末尾,因此應(yīng)該如下所示:hey
what's up?|任何方法都可以做到這一點(diǎn)全瀏覽器?例子:$(document).ready(function(){
$('#insert_caret').click(function()
{
var ele = $('#content');
var length = ele.html().length;
ele.focus();
//set caret -> end pos
}
}
內(nèi)容可編輯,在文本末尾設(shè)置插入符號(hào)(跨瀏覽器)
慕妹3146593
2019-06-28 10:51:28