document.execCommand()FontSize以像素为单位? [英] document.execCommand() FontSize in pixels?

查看:1729
本文介绍了document.execCommand()FontSize以像素为单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 document.execCommand 将字体大小更改为30px(例如)?

How can I change font size to 30px (for example) using document.execCommand?

这:

document.execCommand("fontSize", false, "30px");

不起作用,因为在函数execCommand的第3个参数中,它只允许我输入一个之间且包括1至7的值。

doesn't work, because in 3rd argument of the function execCommand, it only allows me to input a value between and including 1 to 7.

推荐答案

这是的限制的字号命令。我能想到各种各样的选择:

It's a limitation of the FontSize command. There are various options I can think of:


  • 您可以使用CSS类代替并使用 CSS类应用程序模块的rel = noreferrer>瘦长文库;

  • 你可以使用一个哈克方法,如调用 document.execCommand( fontSize的,假7); 然后找到命令创建的元素并根据需要更改它们。请参阅示例: http://jsfiddle.net/S3ctN/ 。这显然取决于是否有任何其他<字体> 在文档中与尺寸7的元件,它也使用依赖于浏览器<字体> 字体大小的元素,似乎都是这样。

  • You could use a CSS class instead and use the CSS class applier module of my Rangy library;
  • You could use a hacky method, such as calling document.execCommand("fontSize", false, "7"); and then finding the elements the command has created and changing them as required. See example: http://jsfiddle.net/S3ctN/. This obviously depends on there being no other <font> elements with size 7 in the document and it also relies on the browser using <font> elements for font size, which it seems they all do.

这篇关于document.execCommand()FontSize以像素为单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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