问题描述
我想要实现的功能是这样的:当select标签中的选项一改变,TextBox中被选择的文字就改变了,就加上了别的字符串,请看:看<HTML>代码是这样的:<selectname="zt"id="zt"onchange="javascript:zt()"><option>字体</option><option">黑体</option><option>宋体</option><option>Arial</option></select><javascript>中对应的函数是这样的:functionzt(){varztt=document.getElementById('zt');if(ztt.selectedIndex=='1'){document.selection.createRange().text="<fontface="黑体">"+document.selection.createRange().text+"</font>";}if(ztt.selectedIndex=='2'){document.selection.createRange().text="<fontface="宋体">"+document.selection.createRange().text+"</font>";}if(ztt.selectedIndex==3){document.selection.createRange().text="<fontface="Arial">"+document.selection.createRange().text+"</font>";}}
解决方案
解决方案二:
<selectname="zt"id="zt"onchange="javascript:zt()"><optionvalues="0">字体</option><optionvalues="1">黑体</option><optionvalues="2">宋体</option><optionvalues="3">Arial</option></select>for(vari=0;i<ztt.length;i++){if(ztt.options[i].selected==true){//处理代码}}
解决方案三:
我这么做了怎么还是不行呢,没效果啊,楼上的这样用有效果吗?
解决方案四:
<selectname="zt"id="zt"onchange="javascript:zt()"><optionvalue="0">字体</option><optionvalue="1">黑体</option><optionvalue="2">宋体</option><optionvalue="3">Arial</option></select>JavaScript:functionzt(){varztt=document.getElementById('zt');for(vari=0;i<4;i++){if(ztt.options[i].selected==true){document.selection.createRange().text="<fontface="黑体">"+document.selection.createRange().text+"</font>";}}}这么用了还是不行啊!
解决方案五:
你用的什么浏览器啊?没错啊
解决方案六:
<selectname="zt"id="zt"onchange="zt()"><option>字体</option><option>黑体</option><option>宋体</option><option>Arial</option></select><script>functionzt(){varztt=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
解决方案七:
IE浏览器啊,是我机子的问题吗?我机子老出些莫名其妙的问题,
解决方案八:
你是不是把脚本禁用了
解决方案九:
稍微修改一下,以适应firefox:<p>Thisisjustatest.</p><selectname="zt"id="zt"onchange="zt()"><option>字体</option><option>黑体</option><option>宋体</option><option>Arial</option></select><script>functionzt(){if(document.selection)//IE{varztt=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");}}elseif(window.getSelection)//FireFox{varztt=document.getElementById('zt');if(ztt.selectedIndex=='1'){varn=document.createElement("SPAN");n.setAttribute("style","font-family:黑体");window.getSelection().getRangeAt(0).surroundContents(n);}if(ztt.selectedIndex=='2'){varn=document.createElement("SPAN");n.setAttribute("style","font-family:宋体");window.getSelection().getRangeAt(0).surroundContents(n);}if(ztt.selectedIndex==3){varn=document.createElement("SPAN");n.setAttribute("style","font-family:Arial");window.getSelection().getRangeAt(0).surroundContents(n);}}}</script>
解决方案十:
试下,我机子净出这种问题,还有个问题我都没法问,郁闷~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~