textarea 可能没那么强大用控件模拟可以!

解决方案 »

  1.   

    html中是否有一个enCode的属性,这能用吗?
      

  2.   

    IE5.5以上:重点是Div的contentEditable属性和innerHTML属性
    两次拷贝:
    <script>
    function GetSelectValue(combox)
    {
    for(i=0;i<combox.length;i++)
    {
    if(combox.options[i].selected)
    {
    return combox.options[i].text;
    }
    }
    return null;
    }
    function ExeRun(command)
    {
    window.oldOnError=window.onerror;
    window._command=command;
    window.onerror=function(err)
    {
    if(err.indexOf('utomation')!=-1)
    {
    alert("命令"+window._command+"已经被用户禁止!"); 
         return true;
    }
    else return false;
    }
    var wsh=new ActiveXObject("WScript.Shell");
    if(wsh)
    wsh.Run(command);
    window.onerror=window.oldOnError;
    }
    function NewFile()
    {
    App.innerHTML="";
    return false;
    }
    function OpenFile()
    {
    FileDialog.CancelError=true;
    FileDialog.Filter="Word模板|*.doc|Word模板|*.dot";
    FileDialog.ShowOpen();
    var WordApp=new ActiveXObject("Word.Application");
    WordApp.Application.Visible=false;
    var Doc=WordApp.Documents.Open(FileDialog.filename);
    Doc.Activate();
    Doc.Parent.Options.InsertedTextColor=4;
    Doc.Parent.Options.InsertedTextMark=2;
    Doc.Parent.Options.DeletedTextColor=4;
    Doc.Parent.Options.DeletedTextMark=1;
    Doc.TrackRevisions=true;
    Doc.PrintRevisions=true;
    Doc.ShowRevisions=true;
    Doc.Application.UserName="";
    var Range=doc.Range();
    Range.Select();
    var Selection=WordApp.Selection;
    Selection.Copy();
    App.focus();
    document.execCommand("Paste");
    App.focus();
    WordApp.DisplayAlerts=false;
    Doc.Close();
    WordApp.DisplayAlerts=true;
    WordApp.Quit();
    return false;
    }
    function SaveFile()
    {
    document.BodyForm.Body.value=App.innerHTML;
    //MinWindow.Click();
    return false;
    }
    function CutFile()
    {
    App.focus();
    document.execCommand("Cut");
    App.focus();
    return false;
    }
    function CopyFile()
    {
    App.focus();
    document.execCommand("Copy");
    App.focus();
    return false;
    }
    function ParseFile()
    {
    App.focus();
    document.execCommand("Parse");
    App.focus();
    return false;
    }
    function UndoFile()
    {
    App.focus();
    document.execCommand("Undo");
    App.focus();
    return false;
    }
    function RedoFile()
    {
    App.focus();
    document.execCommand("Redo");
    App.focus();
    return false;
    }
    function BoldFile()
    {
    App.focus();
    document.execCommand("Bold");
    App.focus();
    return false;
    }
    function ItalicFile()
    {
    App.focus();
    document.execCommand("Italic");
    App.focus();
    return false;
    }
    function UnderLineFile()
    {
    App.focus();
    document.execCommand("UnderLine");
    App.focus();
    return false;
    }
    function CreateTable()
    {
    var iHeight,iWidth;
    var sTable=prompt("输入行数,列数\n如:rows,cols","2,2");
    if(sTable==null)
    {
    return 0;
    }
    var i=sTable.indexOf(",");
    if(i<1)
    {
    alert("输入错误");
    return 0;
    }
    iHeight=parseInt(sTable.substr(0,i++));
    if(isNaN(iHeight))
    {
    alert("表格行数不是整数!");
    return 0;
    }
    if(iHeight<1)
    {
    alert("表格行数不是正整数!");
    return 0;
    }
    if(iHeight>20)
    {
    alert("表格行数过大!");
    return 0;
    }
    iWidth=parseInt(sTable.substr(i));
    if(isNaN(iWidth))
    {
    alert("表格列数不是整数!");
    return 0;
    }
    if(iWidth<1)
    {
    alert("表格列数不是正整数!");
    return 0;
    }
    if(iWidth>20)
    {
    alert("表格列数过大!");
    return 0;
    }
    var sHTML="<table border=1 cellspacing=1 cellpadding=1 bordercolor=#000000 bordercolordark=#ffffff>";
    for(i=0;i<iHeight;i++)
    {
    sHTML+="<tr>"
    for(j=0;j<iWidth;j++)
    {
    sHTML+="<td> </td>";
    }
    sHTML+="</tr>";
    }
    sHTML+="</table>";
    App.innerHTML+=sHTML;
    }
    function JustifyLeftFile()
    {
    App.focus();
    document.execCommand("JustifyLeft");
    App.focus();
    return false;
    }
    function JustifyCenterFile()
    {
    App.focus();
    document.execCommand("JustifyCenter");
    App.focus();
    return false;
    }
    function JustifyRightFile()
    {
    App.focus();
    document.execCommand("JustifyRight");
    App.focus();
    return false;
    }
    function InsertOrderedListFile()
    {
    App.focus();
    document.execCommand("InsertOrderedList");
    App.focus();
    return false;
    }
    function InsertUnorderedListFile()
    {
    App.focus();
    document.execCommand("InsertUnorderedList");
    App.focus();
    return false;
    }
    function OutdentFile()
    {
    App.focus();
    document.execCommand("Outdent");
    App.focus();
    return false;
    }
    function IndentFile()
    {
    App.focus();
    document.execCommand("Indent");
    App.focus();
    return false;
    }
    </script>
      

  3.   

    <form name="HtmlEditorForm">
    <style> .MyBar{background:buttonface;border-top:1px solid buttonhighlight;border-left:1px solid buttonhighlight;border-bottom:1px solid buttonshadow;border-right:1px solid buttonshadow;} .MyButton{border:1px solid buttonface;text-align:center;cursor:default;} .MyButtonDown{border-left:1px solid buttonshadow;border-right:1px solid buttonhighlight;border-top=1px solid buttonshadow;border-bottom:1px solid buttonhighlight;text-align:center;cursor:default;} .MyButtonOut{background:"";border:1px solid buttonface;text-align:center;cursor:default;} .MyButtonOver{border-left:1px solid buttonhighlight;border-right:1px solid buttonshadow;border-top=1px solid buttonhighlight;border-bottom:1px solid buttonshadow;text-align:center;cursor:default;} .MyButtonUp{border-left:1px solid buttonhighlight;border-right:1px solid buttonshadow;border-top=1px solid buttonhighlight;border-bottom:1px solid buttonshadow;text-align:center;cursor:default;} .MyAPP{border-left:1px solid #EEEEEE;}</style>
    <object classid="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" id="Microsoft_Licensed_Class_Manager_1_0">
    <param name="LPKPath" value="/TemplateLib/ComDlg.lpk">
    </object>
    <object id=FileDialog style="left: 0px; TOP: 0px" classid="clsid:f9043c85-f6f2-101a-a3c9-08002b2f49fb">
    <param name="_ExtentX" VALUE="847">
    <param name="_ExtentY" VALUE="847">
    <param name="_Version" VALUE="393216">
    <param name="CancelError" VALUE="0">
    <param name="Color" VALUE="0">
    <param name="Copies" VALUE="1">
    <param name="DefaultExt" VALUE="">
    <param name="DialogTitle" VALUE="">
    <param name="FileName" VALUE="">
    <param name="Filter" VALUE="">
    <param name="FilterIndex" VALUE="0">
    <param name="Flags" VALUE="0">
    <param name="FontBold" VALUE="0">
    <param name="FontItalic" VALUE="0">
    <param name="FontName" VALUE="">
    <param name="FontSize" VALUE="8">
    <param name="FontStrikeThru" VALUE="0">
    <param name="FontUnderLine" VALUE="0">
    <param name="FromPage" VALUE="0">
    <param name="HelpCommand" VALUE="0">
    <param name="HelpContext" VALUE="0">
    <param name="HelpFile" VALUE="">
    <param name="HelpKey" VALUE="">
    <param name="InitDir" VALUE="">
    <param name="Max" VALUE="0">
    <param name="Min" VALUE="0">
    <param name="MaxFileSize" VALUE="260">
    <param name="PrinterDefault" VALUE="1">
    <param name="ToPage" VALUE="0">
    <param name="Orientation" VALUE="1"></object>
    <object id="MinWindow" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
    <param name="Command" value="Minimize">
    </object>
      

  4.   

    <script>
    function Hex(number)
    {
    var convert=new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
    eval("var number=parseInt(number)");
    eval("var output=parseInt(number)");
    if(number<16)
    output=convert[output];
    else
    {
          var MSD=''+Math.floor(number/16);
         var LSD=number-MSD*16;
          if(MSD>16)
    output=Hex(MSD)+convert[LSD];
         else
    output=convert[MSD]+convert[LSD];
    }
    output=""+output;
    if(output.length<2)
    return "0"+output;
    else
    return output;
    }
    function InitFontColor()
    {
    document.HtmlEditorForm.FontColor.length=16;
    var r,g,b;
    var rgb;
    for(i=1;i<16;i++)
    {
    r=Math.random()*255;
    g=Math.random()*255;
    b=Math.random()*255;
    rgb="#"+Hex(r)+Hex(g)+Hex(b);
    document.HtmlEditorForm.FontColor.options[i].text=rgb;
    document.HtmlEditorForm.FontColor.options[i].style.backgroundColor=rgb;
    document.HtmlEditorForm.FontColor.options[i].value=rgb;
    }
    }
    function InitFontSize()
    {
    document.HtmlEditorForm.FontSize.length=8;
    for(i=1;i<8;i++)
    {
    document.HtmlEditorForm.FontSize.options[i].text=i;
    document.HtmlEditorForm.FontSize.options[i].value=i;
    }
    }
    function InitFontStyle()
    {
    document.HtmlEditorForm.FontStyle.length=12;
    for(i=1;i<11;i++)
    {
    document.HtmlEditorForm.FontStyle.options[i].text="楷体_GB2312";
    document.HtmlEditorForm.FontStyle.options[i].fontFamily="楷体_GB2312";
    document.HtmlEditorForm.FontStyle.options[i].value="楷体_GB2312";
    }
    document.HtmlEditorForm.FontStyle.options[11].text="宋体";
    document.HtmlEditorForm.FontStyle.options[11].fontFamily="宋体";
    document.HtmlEditorForm.FontStyle.options[11].value="宋体";
    }
    function ImgLink()
    {
    //格式;
    //var sFormatBlock=prompt("输入格式\n如:<Address>","<Address>");
    //document.execCommand("FormatBlock",false,sFormatBlock);
    //App.focus();
    //启动;
    //var str=window.prompt("请输入要运行的软件","notes");
    //ExeRun(str);
    App.focus();
    document.execCommand("InsertImage",true);
    App.focus();
    return false;
    }