Вопрос

I can make the font bold using a button but not when choosing fonts using the select tag. I have a series of choices such as Arial, Times, Courier etc. with no way of clicking. This is what the code looks like

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

Along with this

<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>
Это было полезно?

Решение

Try changing function fontEditor() to function fontEditor(fontName).

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

And:

<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>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top