Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 比在div contentediate中使用append更好的方法_Javascript_Jquery_Html_Dom_Jquery Plugins - Fatal编程技术网

Javascript 比在div contentediate中使用append更好的方法

Javascript 比在div contentediate中使用append更好的方法,javascript,jquery,html,dom,jquery-plugins,Javascript,Jquery,Html,Dom,Jquery Plugins,我有一个contenteditable div,在这个div中,如果用户在某些内容之后按enter键,就会创建两个break标记 line 1 </br> </br> 但它变成了 line 1 </br> line 2 </br> line 1 </br> </br> html content 第1行 html内容 有没有办法在内容之间不出现两行间距?我也面临同样的问题,有时还会添加“<”、“$gt”等。我使

我有一个contenteditable div,在这个div中,如果用户在某些内容之后按enter键,就会创建两个break标记

line 1
</br>
</br>
但它变成了

line 1
</br>
line 2
</br>
line 1
</br>
</br>
html content
第1行


html内容

有没有办法在内容之间不出现两行间距?

我也面临同样的问题,有时还会添加“<”、“$gt”等。我使用下面的正则表达式删除所有html标记。调用onblur事件时,在函数内部使用以下代码删除标记。即使您将内容复制并粘贴到可编辑的div中,它也可以工作

x = x.replace(/(<[^\\>]*>|<br\/>|&amp;|amp;|&lt|&gt;)/g, '');
x = x.trim();
x=x.replace(/(]*>| | | |和| |< |)/g';
x=x.trim();
希望这就是你要找的

x = x.replace(/(<[^\\>]*>|<br\/>|&amp;|amp;|&lt|&gt;)/g, '');
x = x.trim();