gpt4 book ai didi

javascript - 避免在 contenteditable 区域创建字符串

转载 作者:行者123 更新时间:2023-11-30 05:37:16 25 4
gpt4 key购买 nike

我正在使用这个插件:http://jakiestfu.github.io/Medium.js/docs/改善我的内容可编辑区域,以及类似这样的内容以在单击链接时填充它:

$("#input-content").html(content);

问题是,有时当光标位于 div 的开头时,它会创建如下字符串:

enter image description here

有什么办法可以避免吗?通过 jQuery 或其他方式?

最佳答案

您可以检查任何文本节点 (nodeType === 3)然后用适当的 HTML 标记包装这些节点:

function wrapText(){
$('#yourDiv').contents().filter(
function(){
return this.nodeType === 3;
}).wrap('<p/>');<br/>
}

然后调用wrapTextblur .

关于javascript - 避免在 contenteditable 区域创建字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22941491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com