在文本编辑器中粘贴Word文挡会产生很多冗余代码,欲用Javascript过滤冗余代码,请问怎么捕获Ctrl+V动作和实现"粘贴"按钮事件!求JS代码

解决方案 »

  1.   

    http://ewebeditor.webasp.net/的代码里有,
      

  2.   

    function onPaste() {
    var sHTML = GetClipboardHTML() ;
    var re = /<\w[^>]* class="?MsoNormal"?/gi ;
    if ( re.test(sHTML)){
    if ( confirm( "你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?" ) )
    {
    alert(cleanAndPaste( sHTML )) ;
    }
    }
    }// 清除WORD冗余格式并粘贴
    function cleanAndPaste( html ) {
    // Remove all SPAN tags
    html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
    // Remove Class attributes
    html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    // Remove Style attributes
    html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
    // Remove Lang attributes
    html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    // Remove XML elements and declarations
    html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
    // Remove Tags with XML namespace declarations: <o:p></o:p>
    html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
    // Replace the &nbsp;
    html = html.replace(/&nbsp;/, " " );
    // Transform <P> to <DIV>
    var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
    html = html.replace( re, "<div$2</div>" ) ; return html;
    }// 取剪粘板中的HTML格式数据
    function GetClipboardHTML() {
    var oDiv = document.getElementById("eWebEditor_Temp_HTML")
    oDiv.innerHTML = "" ; var oTextRange = document.body.createTextRange() ;
    oTextRange.moveToElementText(oDiv) ;
    oTextRange.execCommand("Paste") ; var sData = oDiv.innerHTML ;
    oDiv.innerHTML = "" ; return sData ;
    }
      

  3.   

    http://ewebeditor.webasp.net/
    lover(孟子E章) 这个是需要购买的
      

  4.   

    <div class="Btn" TITLE="复制" LANGUAGE="javascript" onclick="format1('copy');">
        <IMG class=Ico height=16 src="images\copy.gif" width=16>
    </div>
    <div class="Btn" TITLE="粘贴" LANGUAGE="javascript" onclick="format1('paste');">
        <IMG class=Ico height=16 src="images\paste.gif" width=16>
    </div>在编辑器页面如上所示,在该JS中function format1(what,opt)怎么搞?
      

  5.   

    实在让各位见笑拉,我对JS甚少研究,一般Down过来直接用,多多包涵啊,希望解决问题先