<div style="width:600px; height:30px;">
<select id="fontfamily" onchange="setFontname()">
<option>字体</option>
<option>宋体</option>
<option>黑体</option>
<option>楷体_GB2312</option>
<option>隶书</option>
<option>幼圆</option>
</select>
<select id="fontfize" onchange="setFontsize()">
<option>字号</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<input value="剪贴" type="button" onclick="oo('cut')" />
<input value="复制" type="button" onclick="oo('copy')" />
<input value="粘贴" type="button" onclick="oo('paste')" />
<input value="加粗" type="button" onclick="oo('bold')" />
<input value="斜体" type="button" onclick="oo('italic')" />
</div><div style="height:300px; width:600px; border:1px solid #000000">
<iframe id="HtmlEditor" src="" frameborder="0" marginheight="0" marginwidth="0" style="width:100%; height:100%;">d</iframe>
<br><br>
</div>
<script>
var f = window.frames["HtmlEditor"];
var html = '<HEAD></HEAD><BODY><div></div></BODY>';
f.document.open("text/html","replace");
f.document.write(html);
f.document.close();
f.document.designMode="on"
function format(type, para){
var f = window.frames["HtmlEditor"];
f.focus();
if(!para) f.document.execCommand(type);
else f.document.execCommand(type,false,para);
f.focus();
}function setFontname(){
var index=document.getElementById("fontfamily").selectedIndex;
if(index!=0) {
var ziti=["字体","宋体","黑体","楷体_GB2312","隶书","幼圆"]
format("fontname",ziti[index]);
}
}
function setFontsize(){
var index=document.getElementById("fontfize").selectedIndex;
if(index!=0)
{var size=["1","2","3","4","5"]
format("fontsize",size[index])
}
}function oo(pp){format(pp)}
</script>
这个以前练手写的一个
跟你写的有个地方不一样
execCommand(type,false,para) 我用的是flase 你用的是true
我把你写的改成false了 就可以正常显示了
我不知道 execCommand的参数是的具体意思 网上都没这些说明,只写了具体怎么用
看看有没有知道的大虾解释一下execCommand
解决方案 »
- vml能否实现画线把区块的部分内容給取出来
- 求JS怎么获取Iframe里面的元素
- extjs 到底好不好用
- 在Firefox中怎样实现滤镜效果?
- 急!在线等待。用Window.Open方法打开一个服务器端存在的文件时,可不可以不管文件类型都提示保存打开确认对话框
- 关于输入框传值至IFRAME的有难度问题
- ExtJs Grid问题!
- 关于拖动的问题
- 关于效率: 用JS 引用,还是用IFRMAE ??
- 怎么样刷新上一页面???
- jquery 最新版是多少? 压缩版 和 未压缩版 都要,给个详细地址 谢谢
- 求:csdn.net中的社区中心里--左边的树形目录代码!!!!!!!!!!!三级菜单(多级)
我搞明白了,不是execCommand(type,false,para)參數用flase還是true 的問題,用哪個好像都行,用true還是用false有什么不同,俺就沒深究研究了,還有其它活要做,暫時放著,有時間在看看。之所以中文字體不能該變是因為簡體繁體的問題。
簡體中文可以改變的字體有,宋體、黑體、楷體、幼圓、仿宋等等,這些字體對于繁體中文就適用了;而繁體中文只能用細明體、新宋體、新細明體等,這些字體對于簡體中文又不適用了。
對于英文字體包括 Arial,Arial Black,Arial Narrow,Comic Sans MS,Courier New,System,Times New Roman,Verdana等等,這些字體不適用于漢字。但是word中這些字體是適用漢字的,具體什么原因沒搞清楚。另外,對于宋體、黑體等這些用于簡體中文的字體作為execCommand的參數時一定要用簡體字,即execCommand('fontname',false,'宋体');如果用繁体的"宋體"了,依然不能改變字體,我就是范了這個錯誤,找了很長時間才找出來。