<select name="zt" id="zt" onchange ="javascript:zt()">
<option values="0" >字体</option>
<option values="1">黑体 </option>
<option values="2">宋体 </option>
<option values="3">Arial </option>
</select> for(var i=0; i<ztt.length; i++)
{
if(ztt.options[i].selected ==true)
{
//处理代码
}
}
function zt()
{
var ztt=document .getElementById ('zt');
for(var i=0;i<4;i++)
{
if(ztt.options [i].selected==true )
{
document .selection.createRange().text="<font face=\"黑体\">"+document .selection.createRange().text+"</font>";
}
}
}这么用了还是不行啊!
<option>字体 </option>
<option>黑体 </option>
<option>宋体 </option>
<option>Arial </option>
</select>
<script>
function zt()
{
var ztt=document.getElementById ('zt');
if(ztt.selectedIndex =='1')
{
document.selection.createRange().execCommand("fontname","","黑体");
}
if(ztt.selectedIndex =='2')
{
document.selection.createRange().execCommand("fontname","","宋体");
}
if(ztt.selectedIndex ==3)
{
document.selection.createRange().execCommand("fontname","","Arial");
}
}
</script>
http://zhidao.baidu.com/question/37778560
<select name="zt" id="zt" onchange="zt()">
<option>字体 </option>
<option>黑体 </option>
<option>宋体 </option>
<option>Arial </option>
</select> <script>
function zt()
{
if (document.selection)//IE
{
var ztt=document.getElementById ('zt');
if(ztt.selectedIndex =='1')
{
document.selection.createRange().execCommand("fontname","","黑体");
}
if(ztt.selectedIndex =='2')
{
document.selection.createRange().execCommand("fontname","","宋体");
}
if(ztt.selectedIndex ==3)
{
document.selection.createRange().execCommand("fontname","","Arial");
}
}
else if (window.getSelection)//FireFox
{
var ztt=document.getElementById ('zt');
if(ztt.selectedIndex =='1')
{
var n = document.createElement("SPAN");
n.setAttribute("style","font-family:黑体");
window.getSelection().getRangeAt(0).surroundContents(n); }
if(ztt.selectedIndex =='2')
{
var n = document.createElement("SPAN");
n.setAttribute("style","font-family:宋体");
window.getSelection().getRangeAt(0).surroundContents(n);
}
if(ztt.selectedIndex ==3)
{
var n = document.createElement("SPAN");
n.setAttribute("style","font-family:Arial");
window.getSelection().getRangeAt(0).surroundContents(n);
}
}
}
</script>