本帖最后由 qiuyuexin 于 2013-12-25 15:58:33 编辑

解决方案 »

  1.   


    SEP_PADDING = 5
    HANDLE_PADDING = 7var yToolbars = new Array();var YInitialized = false;
    function wm(html1)
    {Composition.focus();
    var editTextRange = Composition.document.selection.createRange();
    editTextRange.pasteHTML(html1);
    }
    function forimg()
    {   
      var arr=showModalDialog("selimg.jsp", "", "dialogWidth:30.5em; dialogHeight:15.5em; status:0");
      if (arr != null) wm(arr);
    }function document.onreadystatechange()
    {
      if (YInitialized) return;
      YInitialized = true;  var i, s, curr;  for (i=0; i<document.body.all.length; i++)
      {
        curr=document.body.all[i];
        if (curr.className == "yToolbar")
        {
          InitTB(curr);
          yToolbars[yToolbars.length] = curr;
        }
      }  DoLayout();
      window.onresize = DoLayout;  Composition.document.open()
      Composition.document.write("<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></body>");
      Composition.document.close()
      Composition.document.designMode="On"
    }function InitBtn(btn)
    {
      btn.onmouseover = BtnMouseOver;
      btn.onmouseout = BtnMouseOut;
      btn.onmousedown = BtnMouseDown;
      btn.onmouseup = BtnMouseUp;
      btn.ondragstart = YCancelEvent;
      btn.onselectstart = YCancelEvent;
      btn.onselect = YCancelEvent;
      btn.YUSERONCLICK = btn.onclick;
      btn.onclick = YCancelEvent;
      btn.YINITIALIZED = true;
      return true;
    }function InitTB(y)
    {
      y.TBWidth = 0;  if (! PopulateTB(y)) return false;  y.style.posWidth = y.TBWidth;  return true;
    }
    function YCancelEvent()
    {
      event.returnValue=false;
      event.cancelBubble=true;
      return false;
    }function BtnMouseOver()
    {
      if (event.srcElement.tagName != "IMG") return false;
      var image = event.srcElement;
      var element = image.parentElement;  if (image.className == "Ico") element.className = "BtnMouseOverUp";
      else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";  event.cancelBubble = true;
    }function BtnMouseOut()
    {
      if (event.srcElement.tagName != "IMG") {
        event.cancelBubble = true;
        return false;
      }  var image = event.srcElement;
      var element = image.parentElement;
      yRaisedElement = null;  element.className = "Btn";
      image.className = "Ico";  event.cancelBubble = true;
    }function BtnMouseDown()
    {
      if (event.srcElement.tagName != "IMG") {
        event.cancelBubble = true;
        event.returnValue=false;
        return false;
      }  var image = event.srcElement;
      var element = image.parentElement;  element.className = "BtnMouseOverDown";
      image.className = "IcoDown";  event.cancelBubble = true;
      event.returnValue=false;
      return false;
    }function BtnMouseUp()
    {
      if (event.srcElement.tagName != "IMG") {
        event.cancelBubble = true;
        return false;
      }  var image = event.srcElement;
      var element = image.parentElement;  //if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
      if (navigator.appVersion.match(/8./i)=='8.')
      {
       if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "onclick(event)");
      }
      else
       {
       if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
       }
      element.className = "BtnMouseOverUp";
      image.className = "Ico";  event.cancelBubble = true;
      return false;
    }function PopulateTB(y)
    {
      var i, elements, element;  elements = y.children;
      for (i=0; i<elements.length; i++) {
        element = elements[i];
        if (element.tagName == "SCRIPT" || element.tagName == "!") continue;    switch (element.className) {
        case "Btn":
          if (element.YINITIALIZED == null) {
    if (! InitBtn(element))
    return false;
          }      element.style.posLeft = y.TBWidth;
          y.TBWidth += element.offsetWidth + 1;
          break;    case "TBGen":
          element.style.posLeft = y.TBWidth;
          y.TBWidth += element.offsetWidth + 1;
          break;    case "TBSep":
          element.style.posLeft = y.TBWidth + 2;
          y.TBWidth += SEP_PADDING;
          break;    case "TBHandle":
          element.style.posLeft = 2;
          y.TBWidth += element.offsetWidth + HANDLE_PADDING;
          break;    default:
          return false;
        }
      }  y.TBWidth += 1;
      return true;
    }function DebugObject(obj)
    {
      var msg = "";
      for (var i in TB) {
        ans=prompt(i+"="+TB[i]+"\n");
        if (! ans) break;
      }
    }function LayoutTBs()
    {
      NumTBs = yToolbars.length;  if (NumTBs == 0) return;  var i;
      var ScrWid = (document.body.offsetWidth) - 6;
      var TotalLen = ScrWid;
      for (i = 0 ; i < NumTBs ; i++) {
        TB = yToolbars[i];
        if (TB.TBWidth > TotalLen) TotalLen = TB.TBWidth;
      }  var PrevTB;
      var LastStart = 0;
      var RelTop = 0;
      var LastWid, CurrWid;  var TB = yToolbars[0];
      TB.style.posTop = 0;
      TB.style.posLeft = 0;  var Start = TB.TBWidth;
      for (i = 1 ; i < yToolbars.length ; i++) {
        PrevTB = TB;
        TB = yToolbars[i];
        CurrWid = TB.TBWidth;    if ((Start + CurrWid) > ScrWid) {
          Start = 0;
          LastWid = TotalLen - LastStart;
        }
        else {
          LastWid = PrevTB.TBWidth;
          RelTop -= TB.offsetHeight;
        }    TB.style.posTop = RelTop;
        TB.style.posLeft = Start;
        PrevTB.style.width = LastWid;    LastStart = Start;
        Start += CurrWid;
      }  TB.style.width = TotalLen - LastStart;  i--;
      TB = yToolbars[i];
      var TBInd = TB.sourceIndex;
      var A = TB.document.all;
      var item;
      for (i in A) {
        item = A.item(i);
        if (! item) continue;
        if (! item.style) continue;
        if (item.sourceIndex <= TBInd) continue;
        if (item.style.position == "absolute") continue;
        item.style.posTop = RelTop;
      }
    }function DoLayout()
    {
      LayoutTBs();
    }function validateMode()
    {
      if (! bTextMode) return true;
      alert("请取消“查看HTML源代码”选项再使用系统编辑功能或者提交!");
      Composition.focus();
      return false;
    }function format1(what,opt)
    {
      if (opt=="removeFormat")
      {
        what=opt;
        opt=null;
      }  if (opt==null) Composition.document.execCommand(what);
      else Composition.document.execCommand(what,"",opt);  pureText = false;
      Composition.focus();
    }function format(what,opt)
    {
      if (!validateMode()) return;  format1(what,opt);
    }function setMode(newMode)
    {
      bTextMode = newMode;
      var cont;
      if (bTextMode) {
        cleanHtml();
        cleanHtml();    cont=Composition.document.body.innerHTML;
        Composition.document.body.innerText=cont;
      } else {
        cont=Composition.document.body.innerText;
        Composition.document.body.innerHTML=cont;
      }  Composition.focus();
    }function getEl(sTag,start)
    {
      while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
      return start;
    }function UserDialog(what)
    {
      if (!validateMode()) return;  Composition.document.execCommand(what, true);  pureText = false;
      Composition.focus();
    }function foreColor()
    {
      if (! validateMode()) return;
      var arr = showModalDialog("selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
      if (arr != null) format('forecolor', arr);
      else Composition.focus();
    }function fortable()
    {
      if (! validateMode()) return;
      var arr = showModalDialog("table.html", "", "dialogWidth:13.5em; dialogHeight:10.5em; status:0");
      
      if (arr != null){
      var ss;
      ss=arr.split("*")
      row=ss[0];
      col=ss[1];
      var string;
      string="<table border=1>";
      for(i=1;i<=row;i++){
      string=string+"<tr>";
      for(j=1;j<=col;j++){
      string=string+"<td></td>";
      }
      string=string+"</tr>";
      }
      string=string+"</table>";
      content=Composition.document.body.innerHTML;
      content=content+string;
       Composition.document.body.innerHTML=content;
      }
      else Composition.focus();
    }
    function cleanHtml()
    {
      var fonts = Composition.document.body.all.tags("FONT");
      var curr;
      for (var i = fonts.length - 1; i >= 0; i--) {
        curr = fonts[i];
        if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
      }
    }function getPureHtml()
    {
      var str = "";
      var paras = Composition.document.body.all.tags("P");
      if (paras.length > 0) {
        for (var i=paras.length-1; i >= 0; i--) str = paras[i].innerHTML + "\n" + str;
      } else {
        str = Composition.document.body.innerHTML;
      }
      return str;
    }var bLoad=false
    var pureText=true
    var bodyTag="<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE>"
    var bTextMode=falsepublic_description=new Editorfunction Editor()
    {
      this.put_HtmlMode=setMode;
      this.put_value=putText;
      this.get_value=getText;
    }function getText()
    {
    if (bTextMode)
    return Composition.document.body.innerText;
    else
    {
    cleanHtml();
    cleanHtml();
    return Composition.document.body.innerHTML;
    }
    }function putText(v)
    {
    if (bTextMode)
    Composition.document.body.innerText = v;
    else
    Composition.document.body.innerHTML = v;
    }function InitDocument()
    {
    Composition.document.open();
    Composition.document.write(bodyTag);
    Composition.document.close();
    bLoad=true;
    }
      

  2.   

    经过验证直接部署在线编辑器是没问题的,但是js中一调用就显示不出来了
    <HTML>
    <HEAD>
    <title></title>
     
     
     
    <link rel="stylesheet" type="text/css" href="/ecan/css/text_zh.css"  >
    <link rel="stylesheet" type="text/css" href="/ecan/css/style_zh.css">
    <link rel="stylesheet" type="text/css" href="/ecan/css/themes/air_styles.css">
     
     
     
     
    <script language=JavaScript src = "/ecan/js/global.js"></script>
    </HEAD>
     
    <script Language="JavaScript"> 
    function on()
    {
    var f=document.tPortalNewsitemForm
    f.HTML.value=f.newscontent.value;
     
    }
    function doChangeTemaplate($1){
    var f=document.tPortalNewsitemForm
    if($1==2){
    document.all.htmldiv.style.display="block";
    document.all.textareadiv.style.display="none";
    f.HTML.value=f.newscontent.value;
    }else{
    if(document.all.htmldiv.style.display=="block"){
    document.all.htmldiv.style.display="none";
    document.all.textareadiv.style.display="block";
    f.newscontent.value=f.HTML.value;
    }
    }
    }
    var winscreen;
    function doIt($1){
    if($1 == "Attach") {
    var attache = document.tPortalNewsitemForm.newsfileid.value;
    if (!winscreen || winscreen.closed){
    winscreen =openWindow("/ecan/vfjupload/attach/list.do?configlabel=gmvfjportal&formname=tPortalNewsitemForm&textname=attachmentsname&textvalue=newsfileid&selectvalue="+attache, '', 600, 500,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
    }else{
    winscreen.focus();
    }
    }
    if($1 == "Save") {
    var f=document.tPortalNewsitemForm
    if(document.all.htmldiv.style.display=="block"){
    f.newscontent.value=f.HTML.value;
    }
    if(validateTPortalNewsitemForm(f)){
    f.submit();
    }
    return false;
    }
    if($1 == "Reset") {
    doChangeTemaplate(0);
    }
    if($1 == "Preview") {
    var f=document.tPortalNewsitemForm
    f.newscontent.value=f.HTML.value;
    if(validateTPortalNewsitemForm(f)){
    f.strutsButton.value="preview";
    f.submit();
    return true;
    }
    return false;
    }
    }
     
    </script>
     
     
    <body  onload="doPrompt();on()" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
    <script language=JavaScript>function doPrompt(){}</script>
    <form name="tPortalNewsitemForm" method="post" action="/ecan/vfjportal/TPortalNewsitem/save.do">
    <input type="hidden" name="strutsAction" value="1">
    <input type="hidden" name="strutsButton" value="">
     
     
    <br>
    <table cellpadding="1" cellspacing="1" border="0" width="95%" class="tableBorder" align=center>
    <tr><th class="tableHeaderText" colspan=2 height=25 background="/ecan/images/vfj/portal/td_bg.gif">
     
     【通知通报  频道】增加
     
     
    </th><tr>
    <tr>
    <td width="100%"  class="forumRow">
    <table width="100%" border="0" cellpadding="0" cellspacing="0"  bgcolor="#E4EAF3">
    <input type="hidden" name="newsid" value="0">
    <input type="hidden" name="channelid" value="18">
    <input type="hidden" name="newseditorid" value="0">
    <input type="hidden" name="newsdate" value="">
    <input type="hidden" name="newsreviewid" value="0">
    <input type="hidden" name="newsreviewflag" value="0">
    <input type="hidden" name="visitcount" value="0">
    <tr>
    <td height="25" width="80">
    标题<font color=red>*</font>
    </td>
    <td width="85%">
    <input type="text" name="newstitle" value="" style="width: 300px">
    </td>
    </tr>
    <tr>
    <td height="25" >
    发布单位(署名)<font color=red>*</font>
    </td>
    <td >
    <select name="signid" style="width: 300px">
    <option value="17">办公室</option>
    </select>

    <font color=red>您的组织机构为【<b>办公室</b>】,通常署名应与其保持一致

    </font>
    </td>
    </tr>
    <tr>
    <td height="25" >
    选用模板
    </td>
    <td >


    <input type="radio" name="templateid" value="0" checked="checked" onclick="doChangeTemaplate(0)">

      默认模板



    <input type="radio" name="templateid" value="1" onclick="doChangeTemaplate(1)">

      默认套红模板



    <input type="radio" name="templateid" value="2" onclick="doChangeTemaplate(2)">

      空白模板














    </td>
    </tr>
    <tr>
    <td height="25">
    编号
    </td>
    <td>
    <input type="text" name="newsarchievename" value="" style="width: 300px">
    </td>
    </tr>
    <tr>
    <td height="25">附件
    </td>
    <td>
     
    <table border="0" cellpadding="0" cellspacing="0"  ><tr>
    <td ><input type="text" style="width: 300px" name="attachmentsname" value="" readonly="true"></td>
    <td ><input type="button" class="button" value="上传附件" onclick="doIt('Attach')"></td>
    <input type="hidden" name="newsfileid" value=""><input type="hidden" name="filesize">
    </tr></table>
    </td>
    </tr>
    <tr>
    <td height="100%">
    新闻内容
    </td>
    <td>

    <div id="htmldiv" style="display: none">

    <OBJECT id=HTML data=/ecan/js/editor/editor.html width=100% height=500 type=text/x-scriptlet></object></div>

    <div id="textareadiv" style="display: block">

    <textarea style="width:100%;" rows="20" name="newscontent"></textarea></div>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td height="60" align="right"  bgcolor="#E4EAF3">
    <!--<input type="button" class="button" value="保存" onclick="doIt('Save')"/>&nbsp;&nbsp;-->
    <!--<input type="button" class="button" value="效果预览" onclick="doIt('Preview')"/>&nbsp;&nbsp;-->
    <input type="button" class="button" value="保存" onclick="doIt('Save')"/>
    <input type="reset" class="button" value="重置"  onclick="doIt('Reset')">
    <input type="button" class="button" value="取消" onclick="history.back(-1)">
      </td>
    </tr>
    </table>
     
    </form>
    <script type="text/javascript" language="Javascript1.1"> 
     </script>
     
     
    </body>
    </html>