<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
html = html.replace(/ /, " ");
// 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代码
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
html = html.replace(/ /, " ");
// 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代码
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
另外处理这些代码应该在事件OnClientClick里面处理那个函数你在baidu.com里面是可以找到的
把onclick="Button1_Click"换成
OnClientClick="cleanAndPaste()"
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
html = html.replace(/ /, " ");
// 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);
就不能用,保存后,编辑器的代码还是没有处理过的,这个要怎么弄