在线编HTML辑器(兼容IE和Firefox)

    技术2022-05-11  57

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><style type="text/css">#editor { height:200px; }</style></head>

    <body>

    <p>  <script type="text/javascript">document.writeln("<iframe name=/"editor/" id=/"editor/" width=/"100%/"></iframe>");

    var editor;     editor = document.getElementById("editor").contentWindow;         //只需键入以下设定,iframe立刻变成编辑器。     editor.document.designMode = 'On';     editor.document.contentEditable = true;         //但是IE与FireFox有点不同,为了兼容FireFox,所以必须创建一个新的document。     editor.document.open();     editor.document.writeln('<html><body></body></html>');     editor.document.close();

         //字体特效 - 加粗方法一     function addBold()     {     editor.focus();     //所有字体特效只是使用execComman()就能完成。     editor.document.execCommand("Bold", false, null);     }     function additalic()     {     editor.focus();     //所有字体特效只是使用execComman()就能完成。     editor.document.execCommand("italic", false, null);     }  </script>  <input type="button" name="Submit" value="粗体" οnclick="addBold()" />  <input type="button" name="Submit1" value="斜体" οnclick="additalic()" /></p>

    </body></html> 


    最新回复(0)