首页前端开发其他前端知识用正则表达式格式化html标签的代码

用正则表达式格式化html标签的代码

时间2024-02-01 12:48:03发布访客分类其他前端知识浏览847
导读:收集整理的这篇文章主要介绍了用正则表达式格式化html标签的代码,觉得挺不错的,现在分享给大家,也给大家做个参考。 复制代码 代码如下:<htML> <head>...
收集整理的这篇文章主要介绍了用正则表达式格式化html标签的代码,觉得挺不错的,现在分享给大家,也给大家做个参考。 复制代码 代码如下:
htML>
head>
/head>
body>
style>
#x_edIT{
  height:320px;
  width:540px;
  border:1px solid #666666;

  color:red;

  filter:chroma(color="#0f0f0f");
  background-color:#f0f0f0;
  font-family:verdana;
  font-Size:11px;
  line-height:13px;
  margin-left:16px;
  overflow:scroll;
  border-left:none;
  scrollbar-arrow-color:#666666;
  scrollbar-base-color:#666666;
  scrollbar-darkshadow-color:#f0f0f0;
  scrollbar-face-color:#f0f0f0;
  }
/style>
span onclick="abc()"> 格式化/span>
div contentEditable="true" id="x_edit" style='position:relative; line-height:13px; background-color:#f0f0f0; filter:Chroma(color=#FDFEFF); width:540px; height:320px; overflow:auto; white-space: nowrap;  z-index: 2; border:0px'>
P> & lt; html& gt; br> & lt; head& gt; BR> & lt; /head& gt; BR> & lt; body& gt; BR> & lt; style& gt; BR> #x_edit,#x_edit1{ BR> & nbsp;  height:320px; BR> & nbsp;  width:540px; BR> & nbsp;  border:1px solid #666666; /P>
P> & nbsp;  color:red; /P>
P> & nbsp;  filter:chroma(color="#0f0f0f"); BR> & nbsp;  background-color:#f0f0f0; BR> & nbsp;  font-family:verdana; BR> & nbsp;  font-size:11px; BR> & nbsp;  line-height:13px; BR> & nbsp;  margin-left:16px; BR> & nbsp;  overflow:scroll; BR> & nbsp;  border-left:none; BR> & nbsp;  scrollbar-arrow-color:#666666; BR> & nbsp;  scrollbar-base-color:#666666; BR> & nbsp;  scrollbar-darkshadow-color:#f0f0f0; BR> & nbsp;  scrollbar-face-color:#f0f0f0; BR> & nbsp;  } BR> & lt; /style& gt; BR> & lt; span onclick="abc()"& gt; 试试获得selection的top,然后加上div的scrollTop,然后除以行高& lt; /span& gt; BR> & lt; span id="a" onclick="alert('a')"& gt; a& lt; /span& gt; BR> & lt; span id="b" onclick="alert('b')"& gt; b& lt; /span& gt; BR> & lt; span id="c" onclick="alert('c')"BR> & gt; c& lt; /span& gt; BR> & lt; span id="d" onclick="alert('d')"& gt; d& lt; /span& gt; BR> & lt; span id="e" onclick="alert('e')"& gt; e& lt; /span& gt; BR> & lt; span id="f" onclick="alert('f')"& gt; f& lt; /spanBR> & gt; BR> & lt; span id="g"BR> & nbsp; onclick="alert('g')"& gt; g& lt; /span& gt; BR> & lt; textarea id="x_edit" wrap=off& gt; & lt; /textarea& gt; BR> & lt; div contentEditable="true" id="x_edit1" style='position:relative; line-height:13px; background-color:#f0f0f0; filter:Chroma(color=#FDFEFF); width:540px; height:320px; overflow:auto; white-space: nowrap;  z-index: 2; border:0px'& gt; & lt; /div& gt; BR> & lt; script& gt; BR> function abc(){ BR> & nbsp; & nbsp; & nbsp;  //s=x_edit1.innerText; BR> & nbsp; & nbsp; & nbsp;  VAR s=x_edit.value; BR> & nbsp; & nbsp; & nbsp;  s=s.replace(/\n/gi,""); BR> & nbsp; & nbsp; & nbsp;  //s=s.replace(/& lt; (\w+)(.*?)[^& lt; & gt; ]& gt; /gi,"& lt; "+aaa("$1$2")+"& gt; "); BR> & nbsp; & nbsp; & nbsp;  s=s.replace(/& lt; (.*?)[^& lt; & gt; ]& gt; /gi,"& lt; "+aaa("$1")+"& gt; "); BR> & nbsp; & nbsp; & nbsp;  s=s.replace(/\n/gi,"@"); BR> & nbsp; & nbsp; & nbsp;  //var LineValue=x_edit1.innerText.split("\r")BR> & nbsp; & nbsp; & nbsp;  /*var LineValue=x_edit.value.split("\r")BR> for(var i=0; i& lt; LineValue.length; i++){ BR> & nbsp; & nbsp; & nbsp;  LineValue[i]=LineValue[i].replace(/(".*")/gi,"$1".replace(/& lt; /gi,"\xef").replace(/& gt; /gi,"\xff"))BR> & nbsp; & nbsp; & nbsp;  LineValue[i]=LineValue[i].replace(/& lt; (.*[^& lt; & gt; ])& gt; /gi,"& lt; "+"$1"+"& gt; \r")BR> & nbsp; & nbsp; & nbsp;  LineValue[i]=LineValue[i].replace(/\r\r/gi,"\r")BR> & nbsp; & nbsp; & nbsp;  LineValue[i]=LineValue[i].replace(/(".*")/gi,"$1".replace(/\xef/gi,"& lt; ").replace(/\xff/gi,"& gt; "))BR> } */BR> & nbsp; & nbsp; & nbsp;  //x_edit1.innerText=LineValue.join(""); BR> & nbsp; & nbsp; & nbsp;  //x_edit.value=LineValue.join(""); BR> & nbsp; & nbsp; & nbsp;  x_edit.value=s; BR> & nbsp; & nbsp; & nbsp;  //x_edit1.innerText=s; BR> } BR> function aaa(str){ BR> & nbsp; & nbsp; & nbsp;  str=str.replace(/\r/gi," "); BR> & nbsp; & nbsp; & nbsp;  return str; BR> } BR> & lt; /script& gt; BR> & lt; /body& gt; BR> & lt; /html& gt; /P>
/div>

script>
function abc(){
    var s=x_edit.innerText;
    s=s.replace(/\/?(\w+[\s\S]*?)> /gi,function(a){ return a.replace(/[\r\n]/gi,"")} );
    x_edit.innerText=s;
}
/script>
/body>
/html>
您可能感兴趣的文章:
  • php过滤HTML标签、属性等正则表达式汇总
  • asp自动补全html标签自动闭合(正则表达式)
  • asp.net正则表达式删除指定的HTML标签的代码
  • Java/Js下使用正则表达式匹配嵌套Html标签
  • 移除HTML标签的正则表达式
  • 请教一个正则表达式,匹配所有Html标签外部的指定字符串
  • 使用正则表达式去除所有html标签只保留文字

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

上一篇: 在Asp中用“正则表达式对象”来校...下一篇:js中2005-05-02怎么转换为2005/5...猜你在找的正则表达式相关文章 去除内容中的html2022-04-16Python正则表达式保姆式教学详细教程2022-04-16十分钟上手正则表达式 上篇2022-04-16十分钟上手正则表达式 下篇2022-04-16深入浅出正则表达式中的边界\b和\B2022-04-16轻松入门正则表达式之非贪婪匹配篇详解2022-04-16轻松掌握正则表达式findall函数详解2022-04-16正则表达式用法详解2022-04-1636个正则表达式(开发效率提高80%)2022-04-16Python正则表达式指南 推荐2022-04-16 其他相关热搜词更多phpjavapython程序员loadpost-format-gallery

若转载请注明出处: 用正则表达式格式化html标签的代码
本文地址: https://pptw.com/jishu/595420.html
正则替换字符串功能 &#60;font color=red&#62;原创&#60;/font&#62; JScript中正则表达式用法详解

游客 回复需填写必要信息