早上好,我正在尝试创建文本编辑器并使用以下过程更改字体:
function Select_(selectname, selectname_cor) {
var cursel = document.getElementById(selectname).selectedIndex;
if (cursel != 0) {
var selected = document.getElementById(selectname).options[cursel].value;
if (selectname_cor == "fontsize") {
sel = window.getSelection();
document.execCommand("insertHTML", false, "<font style='font-size:" + selected + "%;'>" + sel + "</font>");
}
document.getElementById(selectname).selectedIndex = 0;
}
document.getElementById("edit").focus();
}
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<select unselectable="on" id="fontsize" onchange="Select_(this.id,'fontsize');">
<option selected="selected" value="Size">Size</option>
<option value="100">100</option>
<option value="150">150</option>
</select>
<div id="edit" style="background:#FFFFCC; height:200px;" contenteditable="true">
</div>
</body>
</html>
但是我得到了不同的结果:在Firefox中,我得到了:
<font style="font-size:140%;">aaaa<font style="font-size:100%;">bbbb</font></font>
在Chrome中,我得到:
<font style="font-size:140%;">aaaa</font><font style="font-size:100%;">bbbb</font>
如何使用Firefox获得chrome的结果?
谢谢!谢谢!谢谢!谢谢!谢谢!