function ButtonOnMouseUp(element)
{
if (event.button == 1)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonReleaseButton(id);
}
}
} function ButtonOnMouseOut(element)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonReleaseButton(id);
}
} function ButtonOnMouseOver(element)
{
    var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonReleaseButton(id);
document.all[BUTTON_DIV_PREFIX + id].className = "ButtonMouseOver";
}
} function ButtonOnClick(element)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
eval(button.action);
}
} function ButtonOnDblClick(element)
{
ButtonOnClick(element);
} function ButtonPushButton(id)
{
document.all[BUTTON_PAD1_PREFIX + id].width = 3;
document.all[BUTTON_PAD1_PREFIX + id].height = 3;
document.all[BUTTON_PAD2_PREFIX + id].width = 1;
document.all[BUTTON_PAD2_PREFIX + id].height = 1;
document.all[BUTTON_DIV_PREFIX + id].className = "ButtonPressed";
} function ButtonReleaseButton(id)
{
document.all[BUTTON_PAD1_PREFIX + id].width = 2;
document.all[BUTTON_PAD1_PREFIX + id].height = 2;
document.all[BUTTON_PAD2_PREFIX + id].width = 2;
document.all[BUTTON_PAD2_PREFIX + id].height = 2;
document.all[BUTTON_DIV_PREFIX + id].className = "ButtonNormal";
}
</SCRIPT>
<SCRIPT>                                                             
    var IMAGE_CHOOSER_DIV_PREFIX = "imageChooserDiv";
    var IMAGE_CHOOSER_IMG_PREFIX = "imageChooserImg";
    var IMAGE_CHOOSER_ICON_PREFIX = "imageChooserIcon";
    var imageChooserMap = new Object();    function ImageChooser
    (
    idGenerator,
    numRows,
    numCols,
    images,
    callback
    )
    {
    this.idGenerator = idGenerator;
    this.numRows = numRows;
    this.numCols = numCols;
    this.images = images;
    this.callback = callback;
    this.Instantiate = ImageChooserInstantiate;
    this.Show = ImageChooserShow;
    this.Hide = ImageChooserHide;
    this.IsShowing = ImageChooserIsShowing;
    this.SetUserData = ImageChooserSetUserData;
    }    function ImageChooserInstantiate()
    {
    this.id = this.idGenerator.GenerateID();
    imageChooserMap[this.id] = this;
    var html = '';
    html += '<div id="' + IMAGE_CHOOSER_DIV_PREFIX + this.id + '" style="display:none;position:absolute;background-color:buttonface;border-left:buttonhighlight solid 1px;border-top:buttonhighlight solid 1px;border-right:buttonshadow solid 1px;border-bottom:buttonshadow solid 1px">';
    html += '<table>';
    for (var i = 0; i < this.numRows; i++) {
    html += '<tr>';
    for (var j = 0; j < this.numCols; j++) {
    html += '<td>';
    var k = i * this.numCols + j;
    html += '<div id="' + IMAGE_CHOOSER_ICON_PREFIX + this.id + '_' + k + '" style="border:buttonface solid 1px">';
    html += '<img src="' + this.images[k] + '" id="' + IMAGE_CHOOSER_IMG_PREFIX + this.id + '_' + k + '" onmouseover="ImageChooserOnMouseOver()" onmouseout="ImageChooserOnMouseOut()" onclick="ImageChooserOnClick()">';
    html += '</div>';
    html += '</td>';
    }
    html += '</tr>';
    }
    html += '</table>';
    html += '</div>';
    document.write(html);
    }    function ImageChooserShow(x, y)
    {
       
        eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.left =x;
    eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.top = y;
    eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.display = "block";
    }    function ImageChooserHide()
    {
    eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.display = "none";
    }    function ImageChooserIsShowing()
    {
    return eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.display == "block";
    }    function ImageChooserSetUserData(userData)
    {
this.userData = userData;
    }    function ImageChooserOnMouseOver()
    {
    
    if (event.srcElement.tagName == "IMG") {
    var underscore = event.srcElement.id.indexOf("_");
    if (underscore != -1) {
    var id = event.srcElement.id.substring(IMAGE_CHOOSER_IMG_PREFIX.length, underscore);
    var index = event.srcElement.id.substring(underscore + 1);
    eval(IMAGE_CHOOSER_ICON_PREFIX + id + "_" + index).style.borderColor = "black";
    }
    }
    }    function ImageChooserOnMouseOut()
    {
       
    if (event.srcElement.tagName == "IMG") {
    var underscore = event.srcElement.id.indexOf("_");
    if (underscore != -1) {
    var id = event.srcElement.id.substring(IMAGE_CHOOSER_IMG_PREFIX.length, underscore);
    var index = event.srcElement.id.substring(underscore + 1);
    eval(IMAGE_CHOOSER_ICON_PREFIX + id + "_" + index).style.borderColor = "buttonface";
    }
    }
    }    function ImageChooserOnClick()
    {
    if (event.srcElement.tagName == "IMG") {
    var underscore = event.srcElement.id.indexOf("_");
    if (underscore != -1) {
    var id = event.srcElement.id.substring(IMAGE_CHOOSER_IMG_PREFIX.length, underscore);
    var imageChooser = imageChooserMap[id];
    imageChooser.Hide();
    var index = event.srcElement.id.substring(underscore + 1);
    if (imageChooser.callback) {
    imageChooser.callback(imageChooser.images[index], imageChooser.userData);
    }
    }
    }
    }
</SCRIPT>
<SCRIPT>                                                             
var EDITOR_COMPOSITION_PREFIX = "editorComposition";
var EDITOR_PARAGRAPH_PREFIX = "editorParagraph";
var EDITOR_LIST_AND_INDENT_PREFIX = "editorListAndIndent";
var EDITOR_TOP_TOOLBAR_PREFIX = "editorTopToolbar";
var EDITOR_BOTTOM_TOOLBAR_PREFIX = "editorBottomToolbar";
var EDITOR_SMILEY_BUTTON_PREFIX = "editorSmileyButton";
var EDITOR_IMAGE_CHOOSER_PREFIX = "editorImageChooser";
var editorMap = new Object();
var editorIDGenerator = null; function Editor(idGenerator)
{
this.idGenerator = idGenerator;
this.textMode = false;
this.brief = false;
this.instantiated = false;
this.Instantiate = EditorInstantiate;
this.GetText = EditorGetText;
this.SetText = EditorSetText;
this.GetHTML = EditorGetHTML;
this.SetHTML = EditorSetHTML;
this.GetBrief = EditorGetBrief;
this.SetBrief = EditorSetBrief;
}

解决方案 »

  1.   

    function EditorInstantiate()
    {
    if (this.instantiated) {
    return;
    }

    this.id = this.idGenerator.GenerateID();
    editorMap[this.id] = this;
    editorIDGenerator = this.idGenerator; var html = "";
    html += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
    html += "<tr bgcolor=dddddd>";
    html += "<td id='" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "' class='Toolbar'>";
    html += "<table cellpaddin='0' cellspacing='0' border='0'>";
    html += "<tr  bgcolor=dddddd>";
    html += "<td>";
    html += "<div class='Space'></div>";
    html += "</td>";
    html += "<td>";
    html += "<div class='Swatch'></div>";
    html += "</td>";
    html += "<td>";
    html += "<select class='List' onchange='EditorOnFont(" + this.id + ", this)'>";
    html += "<option class='Heading'>字体</option>";
    html += "<option value='Arial'>Arial</option>";
    html += "<option value='Arial Black'>Arial Black</option>";
    html += "<option value='Arial Narrow'>Arial Narrow</option>";
    html += "<option value='Comic Sans MS'>Comic Sans MS</option>";
    html += "<option value='Courier New'>Courier New</option>";
    html += "<option value='System'>System</option>";
    html += "<option value='Times New Roman'>Times New Roman</option>";
    html += "<option value='Verdana'>Verdana</option>";
    html += "<option value='Wingdings'>Wingdings</option>";
            html += "<option value='仿宋体'>仿宋体</options>";
            html += "<option value='楷体'>楷体</options>";
            html += "<option value='黑体'>黑体</options>";
            html += "<option value='隶书'>隶书</options>";
            html += "</select>";
    html += "</td>";
    html += "<td>";
    html += "<select class='List' onchange='EditorOnSize(" + this.id + ", this)'>";
    html += "<option class='Heading'>字号</option>";
    html += "<option value='1'>1</option>";
    html += "<option value='2'>2</option>";
    html += "<option value='3'>3</option>";
    html += "<option value='4'>4</option>";
    html += "<option value='5'>5</option>";
    html += "<option value='6'>6</option>";
    html += "<option value='7'>7</option>";
    html += "</select>";
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "<td class='Text'>";
    html += "<input disabled type='checkbox' onclick='EditorOnViewHTMLSource(" + this.id + ", this.checked)'>";
    html += "显示 HTML 代码";
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "</td>";
    html += "</tr>";
    html += "<tr>";
    html += "<td id='" + EDITOR_BOTTOM_TOOLBAR_PREFIX + this.id + "' class='Toolbar'>";
    html += "<table cellpaddin='0' cellspacing='0' border='0'>";
    html += "<tr bgcolor=dddddd>";
    html += "<td>";
    html += "<div class='Space'></div>";
    html += "</td>";
    html += "<td>";
    html += "<div class='Swatch'></div>";
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var cutButton = new Button(";
    html += "editorIDGenerator,";
    html += "'剪切',";
    html += "'EditorOnCut(" + this.id + ")',";
    html += "'images/cut.gif'";
    html += ");";
    html += "cutButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var copyButton = new Button(";
    html += "editorIDGenerator,";
    html += "'复制',";
    html += "'EditorOnCopy(" + this.id + ")',";
    html += "'images/copy.gif'";
    html += ");";
    html += "copyButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var pasteButton = new Button(";
    html += "editorIDGenerator,";
    html += "'粘贴',";
    html += "'EditorOnPaste(" + this.id + ")',";
    html += "'images/paste.gif'";
    html += ");";
    html += "pasteButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var boldButton = new Button(";
    html += "editorIDGenerator,";
    html += "'粗体',";
    html += "'EditorOnBold(" + this.id + ")',";
    html += "'images/bold.gif'";
    html += ");";
    html += "boldButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var italicButton = new Button(";
    html += "editorIDGenerator,";
    html += "'斜体',";
    html += "'EditorOnItalic(" + this.id + ")',";
    html += "'images/italic.gif'";
    html += ");";
    html += "italicButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var underlineButton = new Button(";
    html += "editorIDGenerator,";
    html += "'下划线',";
    html += "'EditorOnUnderline(" + this.id + ")',";
    html += "'images/uline.gif'";
    html += ");";
    html += "underlineButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var foregroundColorButton = new Button(";
    html += "editorIDGenerator,";
    html += "'字体颜色',";
    html += "'EditorOnForegroundColor(" + this.id + ")',";
    html += "'images/tpaint.gif'";
    html += ");";
    html += "foregroundColorButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var backgroundColorButton = new Button(";
    html += "editorIDGenerator,";
    html += "'背景颜色',";
    html += "'EditorOnBackgroundColor(" + this.id + ")',";
    html += "'images/parea.gif'";
    html += ");";
    html += "backgroundColorButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var alignLeftButton = new Button(";
    html += "editorIDGenerator,";
    html += "'左对齐',";
    html += "'EditorOnAlignLeft(" + this.id + ")',";
    html += "'images/aleft.gif'";
    html += ");";
    html += "alignLeftButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var centerButton = new Button(";
    html += "editorIDGenerator,";
    html += "'居中',";
    html += "'EditorOnCenter(" + this.id + ")',";
    html += "'images/center.gif'";
    html += ");";
    html += "centerButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var alignRightButton = new Button(";
    html += "editorIDGenerator,";
    html += "'右对齐',";
    html += "'EditorOnAlignRight(" + this.id + ")',";
    html += "'images/aright.gif'";
    html += ");";
    html += "alignRightButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "<td id='" + EDITOR_LIST_AND_INDENT_PREFIX + this.id + "' style='display:" + (this.brief ? "none" : "inline") + "'>";
    html += "<table cellpadding='0' cellspacing='0' border='0'>";
    html += "<tr>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var numberedListButton = new Button(";
    html += "editorIDGenerator,";
    html += "'编号',";
    html += "'EditorOnNumberedList(" + this.id + ")',";
    html += "'images/nlist.gif'";
    html += ");";
    html += "numberedListButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var bullettedListButton = new Button(";
    html += "editorIDGenerator,";
    html += "'项目符号',";
    html += "'EditorOnBullettedList(" + this.id + ")',";
    html += "'images/blist.gif'";
    html += ");";
      

  2.   

    html += "bullettedListButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var decreaseIndentButton = new Button(";
    html += "editorIDGenerator,";
    html += "'减少缩进',";
    html += "'EditorOnDecreaseIndent(" + this.id + ")',";
    html += "'images/ileft.gif'";
    html += ");";
    html += "decreaseIndentButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var increaseIndentButton = new Button(";
    html += "editorIDGenerator,";
    html += "'增加缩进',";
    html += "'EditorOnIncreaseIndent(" + this.id + ")',";
    html += "'images/iright.gif'";
    html += ");";
    html += "increaseIndentButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += "<div class='Divider'></div>";
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var createHyperlinkButton = new Button(";
    html += "editorIDGenerator,";
    html += "'创建超链接',";
    html += "'EditorOnCreateHyperlink(" + this.id + ")',";
    html += "'images/wlink.gif'";
    html += ");";
    html += "createHyperlinkButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td id='" + EDITOR_SMILEY_BUTTON_PREFIX + this.id + "'>";
    html += UtilBeginScript();
    html += "var insertSmileyButton = new Button(";
    html += "editorIDGenerator,";
    html += "'插入链接图片',";
    html += "'EditorOnCreateImglink(" + this.id + ")',";
    html += "'images/smiley.gif'";
    html += ");";
    html += "insertSmileyButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "</td>";
    html += "</tr>";
            html += "<tr bgcolor=dddddd>";
            html += "<td id='" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "' class='Toolbar'>";
            html += "<input type=hidden name=hidbutton id=hidbutton value="+this.id+">";
            html += "</td>";
    html += "</tr>";
    html += "<tr>";
    html += "<td>";
    html += "<iframe id='" + EDITOR_COMPOSITION_PREFIX + this.id + "' width='100%' height='190'>";
    html += "</iframe>";
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    document.write(html); html = "";
    html += "<body style='font:10pt arial'>";
    html += "</body>";
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.open();
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.write(html);
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.close();
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.designMode = "on";
    //eval(EDITOR_COMPOSITION_PREFIX + this.id).document.onclick = new Function("EditorOnClick(" + this.id + ")"); editorIDGenerator = null;
    this.instantiated = true;
    } function  EditorGetText()
    {
    return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText;
    } function  EditorSetText(text)
    {
    text = text.replace(/\n/g, "<br>");
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML = text;
    } function  EditorGetHTML()
    {
    if (this.textMode) {
    return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText;
    }
    EditorCleanHTML(this.id);
    EditorCleanHTML(this.id);
    return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML;
    } function  EditorSetHTML(html)
    {
    if (this.textMode) {
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText = html;
    }
    else {
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML = html;
    }
    } function EditorGetBrief()
    {
    return this.brief;
    } function EditorSetBrief(brief)
    {
    this.brief = brief;
    var display = this.brief ? "none" : "inline";
    if (this.instantiated) {
    eval(EDITOR_PARAGRAPH_PREFIX + this.id).style.display = display;
    eval(EDITOR_LIST_AND_INDENT_PREFIX + this.id).style.display = display;
    }
    } function EditorOnCut(id)
    {
    EditorFormat(id, "cut");
    } function EditorOnCopy(id)
    {
    EditorFormat(id, "copy");
    } function EditorOnPaste(id)
    {
    EditorFormat(id, "paste");
    } function EditorOnBold(id)
    {
    EditorFormat(id, "bold");
    } function EditorOnItalic(id)
    {
    EditorFormat(id, "italic");
    } function EditorOnUnderline(id)
    {
    EditorFormat(id, "underline");
    } function EditorOnForegroundColor(id)
    {
    if (!EditorValidateMode(id)) {
    return;
    }
    var color = showModalDialog("palette.htm", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:30em");
    if (color) {
    EditorFormat(id, "forecolor", color);
    }
    else { eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    }
    } function EditorOnBackgroundColor(id)
    {
    if (!EditorValidateMode(id)) {
    return;
    }
    var color = showModalDialog("palette.htm", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:30em");
    if (color) {
    EditorFormat(id, "backcolor", color);
    }
    else {
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    }
    } function EditorOnAlignLeft(id)
    {
    EditorFormat(id, "justifyleft");
    } function EditorOnCenter(id)
    {
    EditorFormat(id, "justifycenter");
    } function EditorOnAlignRight(id)
    {
    EditorFormat(id, "justifyright");
    } function EditorOnNumberedList(id)
    {
    EditorFormat(id, "insertOrderedList");
    } function EditorOnBullettedList(id)
    {
    EditorFormat(id, "insertUnorderedList");
    } function EditorOnDecreaseIndent(id)
    {
    EditorFormat(id, "outdent");
    } function EditorOnIncreaseIndent(id)
    {
    EditorFormat(id, "indent");
    }
      

  3.   

    对!就是一个Html编辑器。用起来感觉很爽,而且感觉这么长的程序,用的东西也相当多,把这段代码搞定了,javascript也应该差不多了那个textarea里面的文字设置各种属性,并显示出来,是怎么实现的?textarea本来就支持以Html的样式显示?
    感觉javascript里面的类和函数搞得人挺晕的。都是用function来定义。
    function IDGenerator(nextID)
     { this.nextID = nextID; 
       this.GenerateID = IDGeneratorGenerateID; 
    }          //这个是类?nextID、GenerateID是类成员变量?function IDGeneratorGenerateID()
     { return this.nextID++; } //这个是IDGenerator类的GenerateID成员函数?function Button( idGenerator, caption, action, image )
     { this.idGenerator = idGenerator; 
       this.caption = caption;
       this.action = action; 
       this.image = image;
       this.enabled = true; 
       this.Instantiate = ButtonInstantiate;   //这句话是什么意义?说Button的Instantiate成员函数就是
                            Instantiate成员函数?还是Instantiate只是一个和成员函数同名的成员变量,可是
                            Instantiate函数并无返回值。
       this.Enable = ButtonEnable;
     } function ButtonInstantiate() 
    {}
      

  4.   

    to shitalone(西特龙):
       this.Instantiate = ButtonInstantiate;   //这句话是什么意义?说Button的Instantiate成员函数就是Instantiate成员函数?还是Instantiate只是一个和成员函数同名的成员变量,可是Instantiate函数并无返回值。------------------------------------------------------------------
    可以不需要返回值!
      

  5.   

    superhasty(鸟儿自空中飞过):this.Instantiate = ButtonInstantiate;   那这句话好象感觉没什么意义了。还是有别的用意?我自己做个小例子测试了一下
    txtContent是一个textarea我用txtContent.innerText="......"可以看到文本框里面有内容。
    我换成txtContent.innerHtml="....."却什么都看不到,不知道上面的怎么实现的
      

  6.   

    原來是這個﹐我只關心怎么實現插入的圖片上傳到網站txtContent.innerHtml改成txtContent.innerHTML才對
      

  7.   

    不好意思。继续贴
    function EditorOnCreateHyperlink(id)
    {
    if (!EditorValidateMode(id)) {
    return;
    }
    var anchor = EditorGetElement("A", eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange().parentElement());
    var link = prompt("输入链接地址(如:http://):", anchor ? anchor.href : "http://");
    if (link && link != "http://") {
    if (eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.type == "None") {
    var range = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
    range.pasteHTML('<A HREF="' + link + '"></A>');
    range.select();
    }
    else {
    EditorFormat(id, "CreateLink", link);
    }
    }
    }    function EditorOnCreateImglink(id)
    {
    if (!EditorValidateMode(id)) {
    return;
    }
    var anchor = EditorGetElement("A", eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange().parentElement());
    var link = prompt("输入链接地址(如:http://****/img.jpg):", anchor ? anchor.href : "http://");
    if (link && link != "http://") {
           /// var range = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
    ///range.pasteHTML('<img src="' + link + '">');
    ///range.select();
    EditorOnInsertHtml(id,'<img src="' + link + '">');

    }
    }

    function EditorOnInsertLocImg(imgTag)
    {
    var htmlTag= '<img src="' + imgTag+ '">';
    var gid=document.all["hidbutton"].value; 
    EditorOnInsertHtml(gid,htmlTag);

    } function EditorOnInsertHtml(id,htmlTag)
    {
    var editor = editorMap[id];
    editor.selectionRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();

       // var imgTag = '<img src="' + image + '">';
        var editor = editorMap[id];
        var bodyRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();
        if (bodyRange.inRange(editor.selectionRange)) {
    editor.selectionRange.pasteHTML(htmlTag);
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
        }
        else {
    eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerHTML +=htmlTag;
    editor.selectionRange.collapse(false);
    editor.selectionRange.select();
        }
    } function EditorOnParagraph(id, select)
    {
    EditorFormat(id, "formatBlock", select[select.selectedIndex].value);
    select.selectedIndex = 0;
    } function EditorOnFont(id, select)
    {
    EditorFormat(id, "fontname", select[select.selectedIndex].value);
    select.selectedIndex = 0;
    } function EditorOnSize(id, select)
    {
    EditorFormat(id, "fontsize", select[select.selectedIndex].value);
    select.selectedIndex = 0;
    } function EditorOnViewHTMLSource(id, textMode)
    {
    var editor = editorMap[id];
    editor.textMode = textMode;
    if (editor.textMode) {
    EditorCleanHTML(id);
    EditorCleanHTML(id);
    eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerText = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerHTML;
    }
    else {
    eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerHTML = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerText;
    }
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    } function EditorOnClick(id)
    {
    //eval(EDITOR_IMAGE_CHOOSER_PREFIX + id).Hide();
    }

    function EditorValidateMode(id)
    {
    var editor = editorMap[id];
    if (!editor.textMode) {
    return true;
    }
    alert("要使用工具条,请不要选中\“显示 HTML 代码\”。");
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    return false;
    } function EditorFormat(id, what, opt)
    {
    if (!EditorValidateMode(id)) {
    return;
    }
    if (opt == "removeFormat") {
    what = opt;
    opt = null;
    }
    if (opt == null) {
    eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what);
    }
    else {
    eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what, "", opt);
    }
    } function EditorCleanHTML(id)
    {
    var fonts = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.all.tags("FONT");
    for (var i = fonts.length - 1; i >= 0; i--) {
    var font = fonts[i];
    if (font.style.backgroundColor == "#ffffff") {
    font.outerHTML = font.innerHTML;
    }
    }
    } function EditorGetElement(tagName, start)
    {
    while (start && start.tagName != tagName) {
    start = start.parentElement;
    }
    return start;
    }
    </SCRIPT>
    <SCRIPT>                                                             
    <!-- 
    function SetData()
    {
     document.all["txtSaveplaintext"].value=editor.GetText();
     document.all["txtSaveplainmsg"].value=editor.GetHTML();
     //txtSaveplainmsg.value =editor.GetHTML();
     //plainmsg.innerHTML=editor.GetHTML();
     //alert(plainmsg.innerHTML);
     //alert(editor.GetHTML());
    }
      

  8.   

    这是我的测试品,运行就出意外错误。我已经改成innerHTML了,如果innerHTML="hello";这样的话OK,变成真正的HTML,如<b>hello</b>就歇菜了。
    不知何故。<html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language = 'javascript'>
    function load()
    {
    document.form1.txtTitle.innerHTML = "<a href='sdf'>hello</a>";
    }
    </script>
    </head><body bgcolor="#FFFFFF" text="#000000" onload="load()">
    <form name="form1" method="post" action="">
      <textarea name="txtTitle" cols="50" rows="5"></textarea>
    </form></body>
    </html>
      

  9.   

    太长了,大伙快接。我好继续贴。
    function Switch() {
        
        if (editor.GetText() != "" && editor.GetText() != editor.GetHTML()) {
        conf = confirm("您的邮件将转换为纯文本格式。所有的格式定义都将丢失。是否继续?");
        if (!conf) return;
      }
      document.Compose.Body.value = editor.GetText();
        document.Compose.action = document.Compose.action + "&SWITCH=1";
      document.Compose.submit();
      
      
    }//function document.body.onload.onload() {
      //editor.SetHTML(document.all.plainmsg.innerHTML);
    //}function SetVals() {
        document.Compose.Body.value = editor.GetHTML();
    }
    // -->
    </SCRIPT>
    </HEAD><body text="#000000" bgColor="#819dc5" leftMargin="0" topMargin="0">
    <form name="SubmitRepair" method="post" action="new.aspx" id="SubmitRepair">
      <DIV align="center">
    <TABLE height=7 cellSpacing=0 cellPadding=0 width=778 align=center 
    bgColor=#e9e9e9 border=0>
      <TBODY>
      <TR>
        <TD><FONT face=宋体>&nbsp;</FONT> </TD></TR></TBODY></TABLE>


        <TABLE height=63 cellSpacing=0 cellPadding=0 width=778 align=center border=0>
          <TBODY> 
          <TR> 
            <TD align=middle width=138 bgColor=#e9e9e9>&nbsp;</TD>
          </TR>
          </TBODY>
        </TABLE>
    <TABLE cellSpacing="0" cellPadding="0" width="778" bgColor="#ffffff" border="0">
    <TBODY><TR> <TD vAlign="top" width="140" bgColor="#e9e9e9">&nbsp;
    <TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
    <TBODY>
    <TR>

                  <TD vAlign="top" align="left"> <BR>
                  </TD>
    </TR>
    </TBODY>
    </TABLE>
    </TD>
    <TD width="3" background="images/index_15.gif"></TD>
    <TD style="WIDTH: 643px" vAlign="top" align="left" width=100% colSpan="3" height="300"><br>
              <div id="wrapPane" style="width:100%;">

                <TABLE width=98% cellpadding=0 cellspacing=2 border=0>
                  <TR> 
                    <TD colSpan=6><FONT color=red><span id="showerror"></span></FONT></TD>
                  </TR>
                
                  <TR> 
                    <TD width=12%>维护专题:</TD>
                    <TD width=20%></TD>
                    <TD width=10%>产品类型:</TD>
                    <td width=30%> 
                      <input name="prodname" id="prodname" type="hidden" />
                      <INPUT style="DISPLAY: none" onclick=onSelectProdcate() type=button value=选择>
                      <input name="prodcateid" id="prodcateid" type="hidden" />
                    </TD>
                    <TD width=12%>作者:</TD>
                    <TD width=16%>
                      <input name="author" id="author" type="text" style="WIDTH: 98%" value="hello" />
                  </TR>
                  <TR> 
                    <TD width=12%>关键字:</TD>
                    <td width=60% colspan=3>
                      <input name="key" id="key" type="text" style="width:97.5%" />
                    </td>
                    <td width=12%>系统版本:</td>
                    <td width=16%>
                      <input name="version" id="version" type="text" style="width:98%" />
                    </td>
                  </TR>
                  <TR> 
                    <TD>问题描述:</TD>
                    <TD colSpan=5>
                      <textarea name="detail" id="detail" style="WIDTH: 100%; HEIGHT: 123px" rows="7" cols="64"></textarea>
                    </TD>
                  </TR>
                  <TR> 
                    <TD><FONT face=宋体>发布内容</FONT></TD>
                    <TD bgColor=#dddddd colSpan=5> 
                      <DIV style="LEFT: 0px; POSITION: relative; TOP: 0px; HEIGHT: 250px">
                        <TEXTAREA style="LEFT: 0px; VISIBILITY: hidden; POSITION: absolute; TOP: 0px" name=Body rows=1 cols=20></TEXTAREA>
                        <input name="txtSaveplainmsg" id="txtSaveplainmsg" type="hidden" />
                        <input name="txtSaveplaintext" id="txtSaveplaintext" type="hidden" />
                        <DIV id="plainmsg" style="LEFT: 0px; VISIBILITY: hidden; POSITION: absolute; TOP: 0px"></DIV>
                        <SCRIPT>
    var idGenerator = new IDGenerator(0);
    var editor = new Editor(idGenerator);
    editor.Instantiate();
    </SCRIPT>
                      </DIV>
                    </TD>
                  </TR>
                </TABLE>

    </div><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name="cmdAdd" id="cmdAdd" type="submit" onclick="return OnConfirmAdd()" value="提 交" />&nbsp;&nbsp;&nbsp;&nbsp;
    <BR>
    <br>
    </TD>
    </TR>
    <TR>
    <TD style="HEIGHT: 1px" vAlign="top" width="140" bgColor="#e9e9e9"></TD>
    <TD style="HEIGHT: 1px" width="3" background="images/index_15.gif"></TD>
    <TD style="WIDTH: 642px; HEIGHT: 1px" vAlign="top" align="left" colSpan="3" height="1"><FONT face="宋体"></FONT></TD>
    </TR>
    <tr>
    <TD vAlign="top" align="middle" bgColor="#e9e9e9">
    <TD width="3" background="images/index_15.gif"></TD>
    <TD style="WIDTH: 642px" vAlign="top" align="left" colSpan="3"><br>

              <div align="right">&nbsp; </div>
    </TD>
    </tr>
    <tr>
    <TD style="WIDTH: 785px" vAlign="top" align="left" colSpan="5">
    <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
            <TBODY>
            <TR>
              <TD background=images/buttom.gif height=7><IMG height=7 
                src="images/buttom.gif" width=8></TD></TR></TBODY></TABLE>
            </TD>
          </TR></TBODY></TABLE>
            



    </DIV>
    </form>
    </body>
    </HTML>
      

  10.   

    manyou(他山之石) :为何说实用性不强呢,给文本的显示加上Html的支持的应用的其实也不少,很多论坛、新闻系统也都用的很多。