[分享]分享一个东东,将复制word中内容中的垃圾代码自动去掉
改做.net,好久没回ASP来看看了,分享一个东东给asp的朋友们
功能:将复制word中内容中的垃圾代码自动去掉
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<script>
function GetClipboardHTML()
{
var oDiv = document.getElementById("divTemp")
oDiv.innerHTML = "" ;
var oTextRange = document.body.createTextRange() ;
oTextRange.moveToElementText(oDiv) ;
oTextRange.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
oDiv.innerHTML = "" ;
return sData ;
}
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 ) ;
return html;
}
function Paste()
{
Form1.my.value = cleanAndPaste(GetClipboardHTML());
}
</script>
<Form id="Form1" name="Form1">
<input type="button" value="paste" onclick="Paste()">
<br>
<br>
<textarea name="my" cols="60" rows="10"></textarea>
<DIV id=divTemp
style="VISIBILITY: hidden; OVERFLOW: hidden; WIDTH: 1px; POSITION: absolute; HEIGHT: 1px"></DIV>
</Form>
</BODY>
</HTML>
功能:将复制word中内容中的垃圾代码自动去掉
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<script>
function GetClipboardHTML()
{
var oDiv = document.getElementById("divTemp")
oDiv.innerHTML = "" ;
var oTextRange = document.body.createTextRange() ;
oTextRange.moveToElementText(oDiv) ;
oTextRange.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
oDiv.innerHTML = "" ;
return sData ;
}
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 ) ;
return html;
}
function Paste()
{
Form1.my.value = cleanAndPaste(GetClipboardHTML());
}
</script>
<Form id="Form1" name="Form1">
<input type="button" value="paste" onclick="Paste()">
<br>
<br>
<textarea name="my" cols="60" rows="10"></textarea>
<DIV id=divTemp
style="VISIBILITY: hidden; OVERFLOW: hidden; WIDTH: 1px; POSITION: absolute; HEIGHT: 1px"></DIV>
</Form>
</BODY>
</HTML>
...全文
相关推荐
教师信息技术培训内容(1).doc
**Word、Excel办公自动化**1. 删除空行:通过查找和替换功能,快速去除文章中的空行。2. 工具栏恢复:修复Word工具栏显示异常的问题。3.
2021-2022计算机二级等级考试试题及答案No.17312.docx
内存垃圾回收机制- **知识点**: Java中的自动内存管理机制。- **解析**: 内存垃圾回收机制会自动识别并清理不再被任何对象引用的内存空间,以释放资源。因此,此题的答案为“正确”。
vs2005 c#语言编写的记事本程序
【描述】:“嵌套部分Word文档内容,简单,和大家学习分享一下”这个描述暗示了记事本程序可能具有一个特殊的功能,即能够处理或嵌套显示部分的Word文档内容。
学习制作ppt的资料
- **1.2.6 编制目录** 利用Word 2007的目录功能,可以根据文档中的标题自动创建目录,方便读者查找特定章节。
07版OFFICE培训
- **1.2.8 去掉页眉下面的那条线**:可以通过调整段落格式来移除页眉下的线条。 - **1.2.9 实时翻译**:内置翻译工具可以帮助用户快速翻译文档中的内容。


