日期:2014-05-17  浏览次数:20969 次

请教高手帮我把这段JS改为ASP可调用的!谢谢
这是一段去除烦人的WORD及EXCEL冗余代码(Javascript),只用翻译替换部分,谢谢,就这么多分了,随后再补也可以啊~在线等

<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 )
{
// SPAN
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
// Class
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Style
html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
// Lang
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// XML元素及声明
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
// 带XML名称空间声明: <o:p></o:p>
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
// 替换&nbsp;
html = html.replace(/&nbsp;/, " " );
// 将<P>换成<DIV>
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;// Different because of a IE 5.0 error
html = html.replace( re, "<div$2</div>" ) ;
html = html.replace(/(<T[RD])(\s*)(HEIGHT=[\"\']?\d+[\"\']?)/gi, "$1");
html = html.replace(/(<table)([^>]*?)x:str>/gi, "$1$2align='center'>");
html = html.replace(/(<TD)\s*([^>]*?)(width=[\"\']?\d+[\"\']?)([^>]*?)(>)/gi, "$1$2$4$5");
html = html.replace(/(\s*x:num(=[\"\']\d+")?)(>)/gi, "$3");

//insertHtml( html ) ;

//return html;

Form1.my.value = html;
}

function Paste()
{
var sHTML = GetClipboardHTML() ;

var re = /<\w[^>]* class="?MsoNormal"?/gi ;
var re2 = /<\w[^>]* class="?xl"?/gi ;

if ( re.test( sHTML ) )
{
alert("您要粘贴的内容好像是来自 MS Word,系统将清除 MS Word 格式后再粘贴!")
}

if ( re2.test( sHTML ) )
{
alert("您要粘贴的内容好像是来自 MS Excel,系统将清除 MS Excel 格式后再粘贴!")
}

cleanAndPaste( sHTML ) ;
}

function runCode(code)
{
  var pop=window.open("","_blank");
  pop.document.writeln(code);
  pop.location.reload();
}


function Copy()
{
  document.getElementById("my").select();
  document.execCommand('Copy');
}

</script>

------解决方案--------------------
正则而已。。随手复制粘贴的正则和替换的,自己检查下复制对了没有

VBScript code
function cleanAndPaste( html )
'{
' SPAN
dim rx
set rx=new RegExp
rx.Global=true
rx.IgnoreCase=true
'html = html.replace(/<\/?SPAN[^>]*>/gi, "" )
rx.Pattern="<\/?SPAN[^>]*>"
html=rx.Replace(html,"")
' Class
'html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
rx.Pattern="<(\w[^>]*) class=([^ |>]*)([^>]*)"
html=rx.Replace(html,"<$1$3")
' Style
'html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
rx.Pattern="<(\w[^>]*) style=""([^""]*)""([^>]*)"
html=rx.Replace(html,"<$1$3")
' Lang
'html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
rx.Pattern="<(\w[^>]*) lang=([^ |>]*)([^>]*)"
html=rx.Replace(html,"<$1$3")
' XML元素及声明
'html = h