浏览器会自动插入在CONTENTEDITABLE DIV不需要输入code [英] Browser automatically inserts unwanted code on enter in contenteditable div

查看:187
本文介绍了浏览器会自动插入在CONTENTEDITABLE DIV不需要输入code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与UL和它的一些里的一个CONTENTEDITABLE股利。现在,如果我想补充名单背后的一些更多的文本,我将光标放在最后李(3)后,并按下回车键两次。第一后进入它增加了一个新的利和之后的第二进入它关闭了UL,并增加了一个div里面一个BR,这样我就可以开始在它来写。 (实例#1

I've got a contenteditable div with an ul and some li's in it. Now if I want to add some more text behind the list, I place the cursor after the last li ("3") and hit enter twice. After the first enter it adds a new li and after the second enter it closes the ul and adds a div with a br inside it so that I can start to write in it. (Example #1)

预计code:

<div contenteditable="true">
<p>Test</p>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul><div><br></div>
</div>

这是预期的行为。但是,如果有对李的浏览器不只能添加与BR一个新的div定义的一些样式,但它也可以根据您所定义的样式(增加了不同的code的例2 )。

This is the expected behaviour. But if there are some stylesheets defined for the li's the browser doesn't only add a new div with br but it also adds different code according to the styles you have defined (Example #2).

致使code:

<div contenteditable="true">
<p>Test</p>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul><div><font face="Arial"><span style="line-height: 20px;"><br></span></font></div>
</div>

我能做些什么,以prevent这个浏览器的行为?我也想对李的一些样式,但我不希望浏览器插入不管它喜欢在我的html code。

What can I do to prevent this browser behaviour? I do want to have some stylesheets for the li's but I don't want the browser to insert whatever it likes in my html code.

推荐答案

这是做大组闪烁的和Webkit的(铬,歌剧,Safari浏览器)的错误之一。在CKEditor的的开发站点有一个票分组其中一些我报告说,它也闪烁的和Webkit的网站

This is one of bigger sets of Blink's and Webkit's (Chrome, Opera, Safari) bugs. On CKEditor's dev site there's a ticket grouping some of them and I reported it also on Blink's and Webkit's sites:

  • ​http://code.google.com/p/chromium/issues/detail?id=226941
  • ​https://bugs.webkit.org/show_bug.cgi?id=114791

但没有人回应...; /

but no one responded... ;/

至于有人说,只有两种方法来摆脱这个问题的:

As was said, there are only two ways to get rid of this problem:


  • 编写自己的退格键,删除和enter键的支持(很复杂),

  • 请不要使用任何样式(非常酷)。

所以,恐怕有比当前闪烁提醒和Webkit团队,他们的引擎不应该产生这种蹩脚的HTML没有其他选择。

So I'm afraid that there's no other option currently than reminding Blink and Webkit teams that their engines should not produce this crappy HTML.

这篇关于浏览器会自动插入在CONTENTEDITABLE DIV不需要输入code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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