<asp:Button ID="Button1" runat="server"  Text="取值" onclick="Button1_Click" />这是一个按钮,点击时执行click事件,发布编辑器的内容,现在在页面中取到编辑器中的数据代码(document.getElementById('Editor1').value,这个能够取到html代码)现在用js处理代码中的沉余代码
      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>");
                insertHTML(html);
            }
现在点击button时,处理html沉余代码,怎样调用这里的js,
这个(document.getElementById('Editor1').value)是取到编辑器中的html代码

解决方案 »

  1.   

    OnClientClick参考:
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
      

  2.   

    你用replace这样处理太难了,有一个专门处理html代码转换特殊符函数,用那个处理更好一些。
    另外处理这些代码应该在事件OnClientClick里面处理那个函数你在baidu.com里面是可以找到的
      

  3.   

    OnClientClick="cleanAndPaste(document.getElementById('Editor1').value);"
      

  4.   


    把onclick="Button1_Click"换成
    OnClientClick="cleanAndPaste()"
      

  5.   

    我已经换成<asp:Button ID="Button1" runat="server"  Text="取值" OnClientClick="cleanAndPaste(document.getElementById('Editor1').value);" onclick="Button1_Click" />这样的了,不管用啊
      

  6.   

     <script language="javascript"  type="text/javascript">
                function cleanAndPaste(html) {
                    var html = document.getElementById('Editor1').value;
                    // 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>");
                    alert(html);
                    insertHTML(html);
                }
            </script>现在用这种方法来处理,alert(html)也弹出了处理过的页面,到 insertHTML(html);
    就不能用,保存后,编辑器的代码还是没有处理过的,这个要怎么弄
      

  7.   

    我知道了,已经用过了,没看到我上面的代码吗?现在是弹出框看到处理过的html,但保存后就不行