跨浏览器内容可编辑区域的插件
我需要一个可在所有浏览器+智能手机上运行良好的内容可编辑插件。我尝试了 Codemirror,但它在 iPhone 上运行不佳。然后我尝试了Editarea,它工作得很好,但它有150Kb,使用iframe并且对我来说有很多不必要的代码。我需要的是一个简单的内容可编辑区域,不允许粘贴照片或其他样式的文本,并且在手机上也能很好地工作。
I am in need of a contenteditable plugin that will work well on all browsers + smartphones. I tried Codemirror but it was not working well on iphone. Then I tried Editarea and it works very well, but it is 150Kb, uses an iframe and has a lot of unnecessary code for me. What i need is a simple contenteditable area that will not allow the pasting of photos or other styled text and works well on phones as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能必须编写自己的处理程序,因为您的逻辑是非常自定义的。例如,如果您不想允许粗体显示,则必须禁止使用 ctrl-b 等键盘快捷键。对于粘贴,清理它的最佳策略是将隐藏的 div 注入到内容可编辑区域中,然后将光标放在其中以强制粘贴内容到其中。此时,您可以引用 div 并清除不需要的数据,例如图像。最后,您可以将内容放在 div 后面,然后删除 div。
还要考虑从 Word 粘贴,这可能会非常混乱。在粘贴处理中,您甚至可以使用数据进行 ajax 调用来清理服务器端的数据。
You'll probably have to write your own handler since your logic is very custom. You'll have to disallow keyboard shortcuts like ctrl-b if you do not want to allow bolding for example. For paste, the best strategy to clean it is to inject a hidden div int o your contenteditable area and then place the cursor in it to force the pasted content into it. At that point you can reference the div and clean out unwanted data e.g. images. Finall you can take the content and put it after the div and then remove the div.
Also consider pasting from Word which can be very messy. In the paste handling you can even make an ajax call with the data to clean it server side.