【问题标题】:How do I make an execCommand change the font type for my wysiwyg?如何让 execCommand 更改我所见即所得的字体类型?
【发布时间】:2012-12-20 20:21:57
【问题描述】:

我可以使用按钮使字体加粗,但在使用 select 标签选择字体时不能。我有一系列的选择,如 Arial、Times、Courier 等,无法点击。这就是代码的样子

function fontEditor(){
var x=document.getElementById("fontName").selectedIndex;
var y=document.getElementById("fontName").options;
document.execCommand(x,"",y);
edit.document.focus(fontName);
}

还有这个

<select id="fontName" onChange="fontEditor('font',[selectedIndex].value)">
<option value="Arial">Arial</option>
<option value="Calibri">Calibri</option>
<option value="Comic Sans MS">Comic Sans MS</option>
</select>

【问题讨论】:

  • 不知道你想要达到什么目的......可能想要制作屏幕截图之类的。

标签: javascript execcommand


【解决方案1】:

尝试将function fontEditor() 更改为function fontEditor(fontName)

function fontEditor(fontName) {
    document.execCommand("fontName", false, fontName);
    ...
}

还有:

<select onchange="fontEditor(this[this.selectedIndex].value)">
    <option value="Arial">Arial</option>
    <option value="Calibri">Calibri</option>
    <option value="Comic Sans MS">Comic Sans MS</option>
</select>

【讨论】:

  • 非常感谢,这正是我想做的。我花了几个小时试图修复这个功能。谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-11-30
  • 2015-03-27
  • 2012-07-17
  • 2017-07-10
  • 2014-02-07
  • 1970-01-01
  • 2014-08-21
  • 2011-07-18
相关资源
最近更新 更多