pasteHTML和字体大小 [英] pasteHTML and font size

查看:132
本文介绍了pasteHTML和字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在一个可编辑的div中,我插入了一个大字母Rng.pasteHTML("< font size = 5> A< / font>"); ,精细。然而,在那之后,当键入其他字母时,(有时)我得到大小= 5的大字母。


这是代码:

Hi,

In an editable div, I inserted a big letter, Rng.pasteHTML("<font size=5>A</font>");,fine. However, after that, when type in other letters, (sometimes) I got big letters with size=5.

Here is the code:

展开 | 选择 | Wrap | 行号

推荐答案

@markjavascript


这不是错误。几乎每个富文本编辑器都会这样做。我对MS Word也有同样的问题。如果光标放在该文本旁边,它将被计为标签内部,因此它将具有这些标签的样式。您可以尝试在结束标记之后添加一个空格,以便它不会将游标位置视为标记内部。
@markjavascript
That is not a bug. Just about every rich text editor will do that. I have the same problem with MS Word. If the cursor is placed next to that text it will be counted as inside the tags so it will have the style of those tags. You could try adding a space after the closing tag so that it will not treat the cursors location as inside the tag.


谢谢。

问题是我不能禁止用户在大字母旁边键入字母,因为我的div的字体大小是px,所以无法恢复字体大小。
Thank you.
The problem is that I cannot disallow the user type a letter next to the big letter and there is no way to recover the font size since my div''s font size is in px.


@markjavascript


当然可以。正如我刚才解释的那样,你可以在结束标记之后添加一个空格,这样光标就不会在字母旁边。或者您可以为该字段设置onChange事件,并检查光标是否在您的标记旁边。如果它然后移动一两个空间。




@markjavascript


我不明白你的意思。首先,您不是在px中设置字体大小。您根本不包含该属性的任何标签。其次,您的HTML语法不正确,您应该在所有属性周围引用。第三,要获得字体大小,你需要做的就是读取字体标签的size属性。
@markjavascript
Sure you can. As I just explained you could add a space after the closing tag so the cursor would not end up beside the letter(s). Or you could set an onChange event for the field and check to see if the currsor is next to your tag. If it is then move it over a space or two.





@markjavascript
I do not understand what you mean. First off you are not setting your font size in px. You are not including any label for the attribute at all. Secondly your HTML syntax is incorrect you should have quotes around all of your attributes. Thirdly all you have to do to get the font size is to read the size attribute of the font tag.


这篇关于pasteHTML和字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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