我下了一个帖子的文本编辑器,在a.jsp中引用这个edit.js的代码<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "../jsedit/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
    <form action="donews.jsp" method="post" name="form1">
<textarea name="content" style="width:700; height:350" id="content">
</textarea>

<script language="javascript1.2">
editor_generate('content');
</script>

我发现在a.jsp中不能用document.getElementById("content").value=""之类的东西来控制textarea的值啊。那个edit.js太大了,发不上来了,是不是那个edit.js中设定了textarea不能被其他的代码操控啊。。如果是应该是哪里控制了它呢

解决方案 »

  1.   

    这是edit.js的部分代码看能不能找出来是哪里了document.write('<style type="text/css">\n');
    document.write('.textbtn { width: 22px; height: 22px; border: 1px solid buttonface; margin: 0; padding: 0; }\n');
    document.write('.btnOver { width: 22px; height: 22px; border: 1px outset; }\n');
    document.write('.btnDown { width: 22px; height: 22px; border: 1px inset; background-color: buttonhighlight; }\n');
    document.write('.btnNA   { width: 22px; height: 22px; border: 1px solid buttonface; filter: alpha(opacity=25); }\n');
    document.write('.cMenu   { background-color: threedface; color: menutext; cursor: Default; font-family: MS Sans Serif; font-size: 8pt; padding: 2 12 2 16; }');
    document.write('.cMenuOver { background-color: highlight; color: highlighttext; cursor: Default; font-family: MS Sans Serif; font-size: 8pt; padding: 2 12 2 16; }');
    document.write('.cMenuDivOuter { background-color: threedface; height: 9 }');
    document.write('.cMenuDivInner { margin: 0 4 0 4; border-width: 1; border-style: solid; border-color: threedshadow threedhighlight threedhighlight threedshadow; }');
    document.write('</style>\n');
    /* ---------------------------------------------------------------------- *\
      Function    : editor_defaultConfig
      Description : default configuration settings for wysiwyg editor
    \* ---------------------------------------------------------------------- */function editor_defaultConfig(objname) {this.version = "2.03"this.width =  "auto";
    this.height = "auto";
    this.bodyStyle = 'background-color: #FFFFFF; font-family: "����"; font-size: 12px;';
    this.imgURL = _editor_url + 'images/';
    this.debug  = 0;this.replaceNextlines = 0; // replace nextlines from spaces (on output)
    this.plaintextInput = 0;   // replace nextlines with breaks (on input)this.toolbar = [
        //['fontname'], ///����
        ['fontsize'],
        //['fontstyle'], ///��������
        //['linebreak'], ///����
        ['bold','italic','underline','separator'],
        //['strikethrough','subscript','superscript','separator'], ///������,������,������
        ['justifyleft','justifycenter','justifyright','separator'],
        ['OrderedList','UnOrderedList','Outdent','Indent','separator'],
        ['forecolor','backcolor','separator'],
        //['HorizontalRule','InsertTable','separator'], ///����,����
    ['Createlink','InsertImage','htmlmode','separator'],
        //['custom1','custom2','custom3','separator'],
        ['popupeditor']
    ];this.fontnames = {
        "����":            "����",
        "����":            "����",
        "����_GB2312":     "����_GB2312",
        "����":            "����",
        "Comic Sans MS":   "Comic Sans MS",
        "Arial":           "arial, helvetica, sans-serif",
        "Courier New":     "courier new, courier, mono",
        "Georgia":         "Georgia, Times New Roman, Times, Serif",
        "Tahoma":          "Tahoma, Arial, Helvetica, sans-serif",
        "Times New Roman": "times new roman, times, serif",
        "Verdana":         "Verdana, Arial, Helvetica, sans-serif",
        "impact":          "impact",
        "WingDings":       "WingDings"};this.fontsizes = {
        "1 (8 pt)":  "1",
        "2 (10 pt)": "2",
        "3 (12 pt)": "3",
        "4 (14 pt)": "4",
        "5 (18 pt)": "5",
        "6 (24 pt)": "6",
        "7 (36 pt)": "7"
      };//this.stylesheet = "http://www.xydw.com/sample.css"; // full URL to stylesheetthis.fontstyles = [     // make sure these exist in the header of page the content is being display as well in or they won't work!
    //    { name: "headline",     className: "headline",  classStyle: "font-family: arial black, arial; font-size: 28px; letter-spacing: -2px;" },
    //    { name: "arial red",    className: "headline2", classStyle: "font-family: arial black, arial; font-size: 12px; letter-spacing: -2px; color:red" },
    //    { name: "verdana blue", className: "headline4", classStyle: "font-family: verdana; font-size: 18px; letter-spacing: -2px; color:blue" },
    ];this.btnList = {
        // buttonName:    commandID,               title,                onclick,                   image,             
        "bold":           ['Bold',                 '����',               'editor_action(this.id)',  'ed_format_bold.gif'],
        "italic":         ['Italic',               '����',             'editor_action(this.id)',  'ed_format_italic.gif'],
        "underline":      ['Underline',            '������',          'editor_action(this.id)',  'ed_format_underline.gif'],
        "strikethrough":  ['StrikeThrough',        'Strikethrough',      'editor_action(this.id)',  'ed_format_strike.gif'],
        "subscript":      ['SubScript',            'Subscript',          'editor_action(this.id)',  'ed_format_sub.gif'],
        "superscript":    ['SuperScript',          'Superscript',        'editor_action(this.id)',  'ed_format_sup.gif'],
        "justifyleft":    ['JustifyLeft',          '������',       'editor_action(this.id)',  'ed_align_left.gif'],
        "justifycenter":  ['JustifyCenter',        '����',     'editor_action(this.id)',  'ed_align_center.gif'],
        "justifyright":   ['JustifyRight',         '������',      'editor_action(this.id)',  'ed_align_right.gif'],
        "orderedlist":    ['InsertOrderedList',    '����',       'editor_action(this.id)',  'ed_list_num.gif'],
        "unorderedlist":  ['InsertUnorderedList',  '����2',      'editor_action(this.id)',  'ed_list_bullet.gif'],
        "outdent":        ['Outdent',              '������',    'editor_action(this.id)',  'ed_indent_less.gif'],
        "indent":         ['Indent',               '������',    'editor_action(this.id)',  'ed_indent_more.gif'],
        "forecolor":      ['ForeColor',            '��������',         'editor_action(this.id)',  'ed_color_fg.gif'],
        "backcolor":      ['BackColor',            '��������',   'editor_action(this.id)',  'ed_color_bg.gif'],
        "horizontalrule": ['InsertHorizontalRule', '������',    'editor_action(this.id)',  'ed_hr.gif'],
        "createlink":     ['CreateLink',           '������',    'editor_action(this.id)',  'ed_link.gif'],
        "insertimage":    ['InsertImage',          '��������',       'editor_action(this.id)',  'ed_image.gif'],
        "inserttable":    ['InsertTable',          '��������',       'editor_action(this.id)',  'insert_table.gif'],
        "htmlmode":       ['HtmlMode',             '����HTML',   'editor_setmode(\''+objname+'\')', 'ed_html.gif'],
        "popupeditor":    ['popupeditor',          '������������',     'editor_action(this.id)',  'fullscreen_maximize.gif'],
        "about":          ['about',                '��������',  'editor_about(\''+objname+'\')',  'ed_about.gif'],    // Add custom buttons here:
        "custom1":           ['custom1',         'Purpose of button 1',  'editor_action(this.id)',  'ed_custom.gif'],
        "custom2":           ['custom2',         'Purpose of button 2',  'editor_action(this.id)',  'ed_custom.gif'],
        "custom3":           ['custom3',         'Purpose of button 3',  'editor_action(this.id)',  'ed_custom.gif'],
       // end: custom buttons    "help":           ['showhelp',             'Help using editor',  'editor_action(this.id)',  'ed_help.gif']};
    }/* ---------------------------------------------------------------------- *\
      Function    : editor_generate
      Description : replace textarea with wysiwyg editor
      Usage       : editor_generate("textarea_id",[height],[width]);
      Arguments   : objname - ID of textarea to replace
                    w       - width of wysiwyg editor
                    h       - height of wysiwyg editor
    \* ---------------------------------------------------------------------- */
    function editor_generate(objname,userConfig) {  // Default Settings
      var config = new editor_defaultConfig(objname);
      if (userConfig) { 
        for (var thisName in userConfig) {
          if (userConfig[thisName]) { config[thisName] = userConfig[thisName]; }
        }
      }
      document.all[objname].config = config;                  // store config settings  // set size to specified size or size of original object
      var obj    = document.all[objname];
      if (!config.width || config.width == "auto") {
        if      (obj.style.width) { config.width = obj.style.width; }      // use css style
        else if (obj.cols)        { config.width = (obj.cols * 8) + 22; }  // col width + toolbar
        else                      { config.width = '100%'; }               // default
      }
      if (!config.height || config.height == "auto") {
        if      (obj.style.height) { config.height = obj.style.height; }   // use css style
        else if (obj.rows)         { config.height = obj.rows * 17 }       // row height
        else                       { config.height = '200'; }              // default
      }
      

  2.   


      var tblOpen  = '<table border=0 cellspacing=0 cellpadding=0 style="float: left;"  unselectable="on"><tr><td style="border: none; padding: 1 0 0 0"><nobr>';
      var tblClose = '</nobr></td></tr></table>\n';  // build button toolbar  var toolbar = '';
      var btnGroup, btnItem, aboutEditor;
      for (var btnGroup in config.toolbar) {    // linebreak
        if (config.toolbar[btnGroup].length == 1 &&
            config.toolbar[btnGroup][0].toLowerCase() == "linebreak") {
          toolbar += '<br clear="all">';
          continue;
        }    toolbar += tblOpen;
        for (var btnItem in config.toolbar[btnGroup]) {
          var btnName = config.toolbar[btnGroup][btnItem].toLowerCase();      // fontname
          if (btnName == "fontname") {
            toolbar += '<select id="_' +objname+ '_FontName" onChange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 2; font-size: 12px;">';
            for (var fontname in config.fontnames) {
              toolbar += '<option value="' +config.fontnames[fontname]+ '">' +fontname+ '</option>'
            }
            toolbar += '</select>';
            continue;
          }      // fontsize
          if (btnName == "fontsize") {
            toolbar += '<select id="_' +objname+ '_FontSize" onChange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 12px;">';
            for (var fontsize in config.fontsizes) {
              toolbar += '<option value="' +config.fontsizes[fontsize]+ '">' +fontsize+ '</option>'
            }
            toolbar += '</select>\n';
            continue;
          }      // font style
          if (btnName == "fontstyle") {
            toolbar += '<select id="_' +objname+ '_FontStyle" onChange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 12px;">';
            + '<option value="">Font Style</option>';
            for (var i in config.fontstyles) {
              var fontstyle = config.fontstyles[i];
              toolbar += '<option value="' +fontstyle.className+ '">' +fontstyle.name+ '</option>'
            }
            toolbar += '</select>';
            continue;
          }      // separator
          if (btnName == "separator") {
            toolbar += '<span style="border: 1px inset; width: 1px; font-size: 16px; height: 16px; margin: 0 3 0 3"></span>';
            continue;
          }      // buttons
          var btnObj = config.btnList[btnName];
          if (btnName == 'linebreak') { alert("htmlArea error: 'linebreak' must be in a subgroup by itself, not with other buttons.\n\nhtmlArea wysiwyg editor not created."); return; }
          if (!btnObj) { alert("htmlArea error: button '" +btnName+ "' not found in button list when creating the wysiwyg editor for '"+objname+"'.\nPlease make sure you entered the button name correctly.\n\nhtmlArea wysiwyg editor not created."); return; }
          var btnCmdID   = btnObj[0];
          var btnTitle   = btnObj[1];
          var btnOnClick = btnObj[2];
          var btnImage   = btnObj[3];
          toolbar += '<button title="' +btnTitle+ '" id="_' +objname+ '_' +btnCmdID+ '" class="textbtn" onClick="' +btnOnClick+ '" onmouseover="if(this.className==\'textbtn\'){this.className=\'btnOver\'}" onmouseout="if(this.className==\'btnOver\'){this.className=\'textbtn\'}" unselectable="on"><img src="' +config.imgURL + btnImage+ '" border=0 unselectable="on"></button>';
        } // end of button sub-group
        toolbar += tblClose;
      } // end of entire button set  // build editor  var editor = '<span id="_editor_toolbar"><table border=0 cellspacing=0 cellpadding=0 bgcolor="buttonface" style="padding: 1 0 0 2" width=' + config.width + ' unselectable="on"><tr><td>\n'
      + toolbar
      + '</td></tr></table>\n'
      + '</td></tr></table></span>\n'
      + '<textarea ID="_' +objname + '_editor" style="width:' +config.width+ '; height:' +config.height+ '; margin-top: -1px; margin-bottom: -1px;" wrap=soft></textarea>';  // add context menu
      editor += '<div id="_' +objname + '_cMenu" style="position: absolute; visibility: hidden;"></div>';  //  hide original textarea and insert htmlarea after it
      if (!config.debug) { document.all[objname].style.display = "none"; }  if (config.plaintextInput) {     // replace nextlines with breaks
        var contents = document.all[objname].value;
        contents = contents.replace(/\r\n/g, '<br>');
        contents = contents.replace(/\n/g, '<br>');
        contents = contents.replace(/\r/g, '<br>');
        document.all[objname].value = contents;
      }  // insert wysiwyg
      document.all[objname].insertAdjacentHTML('afterEnd', editor)  // convert htmlarea from textarea to wysiwyg editor
      editor_setmode(objname, 'init');  // call filterOutput when user submits form
      for (var idx=0; idx < document.forms.length; idx++) {
        var r = document.forms[idx].attachEvent('onsubmit', function() { editor_filterOutput(objname); });
        if (!r) { alert("Error attaching event to form!"); }
      }return true;}/* ---------------------------------------------------------------------- *\
      Function    : editor_action
      Description : perform an editor command on selected editor content
      Usage       :
      Arguments   : button_id - button id string with editor and action name
    \* ---------------------------------------------------------------------- */function editor_action(button_id) {  // split up button name into "editorID" and "cmdID"
      var BtnParts = Array();
      BtnParts = button_id.split("_");
      var objname    = button_id.replace(/^_(.*)_[^_]*$/, '$1');
      var cmdID      = BtnParts[ BtnParts.length-1 ];
      var button_obj = document.all[button_id];
      var editor_obj = document.all["_" +objname + "_editor"];
      var config     = document.all[objname].config;  // help popup
      if (cmdID == 'showhelp') {
        window.open(_editor_url + "popups/editor_help.html", 'EditorHelp');
        return;
      }  // popup editor
      if (cmdID == 'popupeditor') {
        window.open(_editor_url + "popups/fullscreen.html?"+objname,
                    'FullScreen',
                    'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=640,height=480');
        return;
      }  // check editor mode (don't perform actions in textedit mode)
      if (editor_obj.tagName.toLowerCase() == 'textarea') { return; }  var editdoc = editor_obj.contentWindow.document;
      editor_focus(editor_obj);  // get index and value for pulldowns
      var idx = button_obj.selectedIndex;
      var val = (idx != null) ? button_obj[ idx ].value : null;  if (0) {}   // use else if for easy cutting and pasting  //
      // CUSTOM BUTTONS START HERE
      //  // Custom1
      else if (cmdID == 'custom1') {
        alert("Hello, I am custom button 1!");
      }  // Custom2
      else if (cmdID == 'custom2') {  // insert some text from a popup window
        var myTitle = "This is a custom title";
        var myText = showModalDialog(_editor_url + "popups/custom2.html",
                                     myTitle,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                     "resizable: yes; help: no; status: no; scroll: no; ");
        if (myText) { editor_insertHTML(objname, myText); }
      }  // Custom3
      else if (cmdID == 'custom3') {  // insert some text
        editor_insertHTML(objname, "It's easy to add buttons that insert text!");
      }
      

  3.   

    // Custom3
      else if (cmdID == 'custom3') {  // insert some text
        editor_insertHTML(objname, "It's easy to add buttons that insert text!");
      }  //
      // END OF CUSTOM BUTTONS
      //  // FontName
      else if (cmdID == 'FontName' && val) {
        editdoc.execCommand(cmdID,0,val);
      }  // FontSize
      else if (cmdID == 'FontSize' && val) {
        editdoc.execCommand(cmdID,0,val);
      }  // FontStyle (change CSS className)
      else if (cmdID == 'FontStyle' && val) {
        editdoc.execCommand('RemoveFormat');
        editdoc.execCommand('FontName',0,'636c6173734e616d6520706c616365686f6c646572');
        var fontArray = editdoc.all.tags("FONT");
        for (i=0; i<fontArray.length; i++) {
          if (fontArray[i].face == '636c6173734e616d6520706c616365686f6c646572') {
            fontArray[i].face = "";
            fontArray[i].className = val;
            fontArray[i].outerHTML = fontArray[i].outerHTML.replace(/face=['"]+/, "");
            }
        }
        button_obj.selectedIndex =0;
      }  // fgColor and bgColor
      else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
        var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));
        var newcolor = showModalDialog(_editor_url + "popups/select_color.html", oldcolor, "resizable: no; help: no; status: no; scroll: no;");
        if (newcolor != null) { editdoc.execCommand(cmdID, false, "#"+newcolor); }
      }  // execute command for buttons - if we didn't catch the cmdID by here we'll assume it's a
      // commandID and pass it to execCommand().   See http://msdn.microsoft.com/workshop/author/dhtml/reference/commandids.asp
      else {
        // subscript & superscript, disable one before enabling the other
        if (cmdID.toLowerCase() == 'subscript' && editdoc.queryCommandState('superscript')) { editdoc.execCommand('superscript'); }
        if (cmdID.toLowerCase() == 'superscript' && editdoc.queryCommandState('subscript')) { editdoc.execCommand('subscript'); }    // insert link
        if (cmdID.toLowerCase() == 'createlink'){
          editdoc.execCommand(cmdID,1);
        }    // insert image
        else if (cmdID.toLowerCase() == 'insertimage'){
          showModalDialog(_editor_url + "popups/insert_image.html", editdoc, "resizable: no; help: no; status: no; scroll: no; ");
        }    // insert table
        else if (cmdID.toLowerCase() == 'inserttable'){
          showModalDialog(_editor_url + "popups/insert_table.html?"+objname,
                                     window,
                                     "resizable: yes; help: no; status: no; scroll: no; ");
        }    // all other commands microsoft Command Identifiers
        else { editdoc.execCommand(cmdID); }
      }  editor_event(objname);
    }/* ---------------------------------------------------------------------- *\
      Function    : editor_event
      Description : called everytime an editor event occurs
      Usage       : editor_event(objname, runDelay, eventName)
      Arguments   : objname - ID of textarea to replace
                    runDelay: -1 = run now, no matter what
                              0  = run now, if allowed
                            1000 = run in 1 sec, if allowed at that point
    \* ---------------------------------------------------------------------- */function editor_event(objname,runDelay) {
      var config = document.all[objname].config;
      var editor_obj  = document.all["_" +objname+  "_editor"];       // html editor object
      if (runDelay == null) { runDelay = 0; }
      var editdoc;
      var editEvent = editor_obj.contentWindow ? editor_obj.contentWindow.event : event;  // catch keypress events
        if (editEvent && editEvent.keyCode) {
          var ord       = editEvent.keyCode;    // ascii order of key pressed
          var ctrlKey   = editEvent.ctrlKey;
          var altKey    = editEvent.altKey;
          var shiftKey  = editEvent.shiftKey;      if (ord == 16) { return; }  // ignore shift key by itself
          if (ord == 17) { return; }  // ignore ctrl key by itself
          if (ord == 18) { return; }  // ignore alt key by itself
           // cancel ENTER key and insert <BR> instead
    //       if (ord == 13 && editEvent.type == 'keypress') {
    //         editEvent.returnValue = false;
    //         editor_insertHTML(objname, "<br>");
    //         return;
    //       }      if (ctrlKey && (ord == 122 || ord == 90)) {     // catch ctrl-z (UNDO)
    //      TODO: Add our own undo/redo functionality
    //        editEvent.cancelBubble = true;
            return;
          }
          if ((ctrlKey && (ord == 121 || ord == 89)) ||
              ctrlKey && shiftKey && (ord == 122 || ord == 90)) {     // catch ctrl-y, ctrl-shift-z (REDO)
    //      TODO: Add our own undo/redo functionality
            return;
          }
        }  // setup timer for delayed updates (some events take time to complete)
      if (runDelay > 0) { return setTimeout(function(){ editor_event(objname); }, runDelay); }  // don't execute more than 3 times a second (eg: too soon after last execution)
      if (this.tooSoon == 1 && runDelay >= 0) { this.queue = 1; return; } // queue all but urgent events
      this.tooSoon = 1;
      setTimeout(function(){
        this.tooSoon = 0;
        if (this.queue) { editor_event(objname,-1); };
        this.queue = 0;
        }, 333);  // 1/3 second
      editor_updateOutput(objname);
      editor_updateToolbar(objname);}
      

  4.   

    jsp是服务器端的。document.getElementById("content").value=""是一句javasript语句。应用在客户端。好像应该是不能改的。