避免ie contentEditable元素在Enter键上创建段落 [英] avoid ie contentEditable element to create paragraphs on Enter key

查看:70
本文介绍了避免ie contentEditable元素在Enter键上创建段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在InternetExplorer上,每次按Enter键时,contentEditable DIV都会创建一个新段落(< p>< / p> ),而Firefox会创建< br /> 标记。
是否可以强制IE插入< br /> 而不是新的段落?

解决方案

是的,可以通过先停止keydown事件来避免插入段落( window.event.stopPropagation(); ),然后使用插入 HTML命令插入字符串。



然而,IE依赖于这个divs来设置样式等等,你会用< br> s来麻烦。

我建议您使用诸如 TinyMCE或其他编辑器的项目并搜索一个表现得很好的编辑器你喜欢的方式,因为他们有不同的浏览器问题的各种解决方法。也许你可以找到一个编辑器来使用< br> s ...


On InternetExplorer, a contentEditable DIV creates a new paragraph (<p></p>) each time you press Enter whereas Firefox creates a <br/> tag. Is it possible to force IE to insert a <br/> instead of a new paragraph ?

解决方案

Yes it is possible to avoid the insertion of paragraphs by stopping the keydown event first (window.event.stopPropagation();) and then inserting the string by using insert HTML command.

However, IE depends on this divs for setting styles etc. and you will get into trouble using <br>s.

I suggest you using a project like TinyMCE or other editors and search for an editor which behaves the way you would like, since they have all kinds of workarounds for different browser issues. Perhaps you can find an editor which uses <br>s...

这篇关于避免ie contentEditable元素在Enter键上创建段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆