如何处理wysihtml5的br和nbsp? [英] How to handle wysihtml5`s br and nbsp?
问题描述
我正在使用wysihtml5编辑器,输出出现问题.
I'm using wysihtml5 editor and having some problems with the output.
当我按下回车键时,我得到了一个换行符,但是没有正确的XHTML标记.它使用<br>
而不是<br />
.
When I hit return I get a line break which is OK, but the tag isn't valid XHTML. It uses <br>
instead of <br />
.
我遇到的另一个问题是当我创建两个空间时.然后,我得到
元素,这会使我的XML解析器失败..
The other problem I experienced is when I create two spaces. I then get the
element, which makes my XML parser fail..
任何人都知道如何消除这些情况吗?
Anyone know how to remove these from occurring?
推荐答案
以下代码提供了文本内容(无html标签)和html内容(有html标签).谁想要谁?
The following codes provide text content(without html tags) and html content(with html tags). Who wants which of them;
textContent = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.textContent;
htmlContent = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.innerHTML;
我的建议是,在监听诸如keydown
,keyup
和keypress
之类的事件时,不应使用jQuery来到达对象.它无法正常工作.
And my advice is that you shouldn't use jQuery for reaching the object when you listen events like keydown
, keyup
and keypress
. It doesn't work properly.
以下代码最适合我;
$('.wysihtml5-sandbox').contents().find('body').on("keyup",function() {
var content = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.textContent;
var contentLength = content.length;
var remaining = 2500-contentLength;
$("#characterCount").text(remaining);
});
这篇关于如何处理wysihtml5的br和nbsp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!