千分给一人!!求助关于格式转换问题!!!!

islandnet 2003-12-28 01:53:06
有一款再线html文档编辑器提供从word中复制转换功能。


可以把word文当中的格式给去掉。


但其中有些瑕疵。导致,每缎文章开头原来空两个,他却不空。一股脑儿的把所有style给去掉。


下面我贴出实例文档代码。供参考

<P style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一排不空
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第二排空两个字
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第三排空两个字
<P style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第四排不空
<P style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第五排不空
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第六排空三个字
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第七排空三个字。</SPAN></P></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>

以上是事例代码。


下面是转换函数


function word()
{
HtmlEdit.document.execCommand("Paste",false);
var editBody=HtmlEdit.document.body;
for(var intLoop=0;intLoop el=editBody.all[intLoop];
el.removeAttribute("className","",0);
el.removeAttribute("style","",0);
el.removeAttribute("font","",0);
}
var html=HtmlEdit.document.body.innerHTML;
html=html.replace(/ <\/o:p>/g,"");
html=html.replace(/o:/g,"");
html=html.replace(//g, "");
html=html.replace(//g, "");
html=html.replace(//g, "");
html=html.replace(//g, "");
html=html.replace(//g, "");
html=html.replace(/

/g, "");
html=html.replace(/<\/P>/g, "");
html=html.replace(/<\/SPAN>/g, "");
HtmlEdit.document.body.innerHTML = html;
format('selectall');
format('RemoveFormat');
}




好了。我们来分析一下。这个转换函数一股脑儿把所有代码给replace掉了。
转换函数没有分析这个


中是否有style=''"
现在需要修改成,遇到style=""则不过滤掉

具体怎么修改呢!?请高人赐教。谢谢


请搞人在那个转换函数基础上修改。如成功,分数全给您
...全文
85 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
islandnet 2003-12-29
  • 打赏
  • 举报
回复
Jaron(唐伯虎点蚊香)谢谢你。
搞定了。

给你1000分。具体怎样才能给呢!!要不我在出几个空铁子。你来,我给你。
先给你100分八。
dreamfly8848 2003-12-28
  • 打赏
  • 举报
回复
up
snowcloud2002 2003-12-28
  • 打赏
  • 举报
回复
学习。。
aojiankd 2003-12-28
  • 打赏
  • 举报
回复
up
shdcxue 2003-12-28
  • 打赏
  • 举报
回复
up
Ranmei 2003-12-28
  • 打赏
  • 举报
回复
关注
孟子E章 2003-12-28
  • 打赏
  • 举报
回复
其实最好把word用程序转换为txt格式最好。word太乱了
Jaron 2003-12-28
  • 打赏
  • 举报
回复
根据需要,注释掉相应行。
Jaron 2003-12-28
  • 打赏
  • 举报
回复
try this:

<script language=javascript>
<!--
function cleanWordString( html ) {
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );// Remove all SPAN tags
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ; // Remove Class attributes
//html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ; // Remove Style attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;// Remove Lang attributes
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;// Remove XML elements and declarations
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/ /, " " );// Replace the  
// 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 ) ;
test.b.value = html
}
//-->
</script>
<form id=test>
<textarea name=a cols=60 rows=13></textarea><br>
<textarea name=b cols=60 rows=13 ID="b"></textarea>
<input type=button onclick="cleanWordString(test.a.value);" value=转换>
</form>
qunluo 2003-12-28
  • 打赏
  • 举报
回复
楼上值得收藏!
Jaron 2003-12-28
  • 打赏
  • 举报
回复
function cleanAndPaste( html ) {
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );// Remove all SPAN tags
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;// Remove Class attributes
html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;// Remove Style attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;// Remove Lang attributes
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;// Remove XML elements and declarations
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/ /, " " );// Replace the  
// 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 ) ;
}
islandnet 2003-12-28
  • 打赏
  • 举报
回复

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧