一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - 正則表達式 - 用正則表達式格式化html標簽的代碼

用正則表達式格式化html標簽的代碼

2020-07-12 17:25正則表達式教程網 正則表達式

本文主要講解用正則表達式格式化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;/span<BR>&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>

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 免费成年网站 | 天天射天天舔 | 男人天堂中文字幕 | 亚洲香蕉伊在人在线观看9 亚洲系列国产系列 | 欧洲另类一二三四区 | 午夜国产精品视频在线 | 脱jk裙的美女露小内内无遮挡 | 我的妹妹最近有点怪免费播放 | 亚洲AV久久无码精品九九软件 | 亚洲精品www久久久久久久软件 | 欧美亚洲高清日韩成人 | 国模孕妇季玥337p人体 | 欧美视频在线一区 | 欧美日韩国产超高清免费看片 | 亚洲天堂影视 | 被黑人同学彻底征服全文小说阅读 | 亚洲欧美一区二区三区在饯 | 国产成人高清亚洲一区91 | 国产午夜精品久久久久 | 亚洲天堂男人 | 成人在线免费观看 | 91精品免费国产高清在线 | 免费一级国产生活片 | 男人狂躁女人下面的视频免费 | 国产精品色图 | 公交车强校花系列小说 | 18young第一次 | 国产精品嫩草影院一二三区 | 国产精品成人免费观看 | 9久re在线观看视频精品 | 亚洲成年人免费网站 | 国内精品久久久久久久久久久久 | 国内精品一区视频在线播放 | pppd在线播放 | 日韩欧美中文字幕一区二区三区 | 国产精品久久久久一区二区三区 | 国语第一次处破女 | 视频精品一区二区三区 | 天干夜天天夜天干天ww | 奶茶视频有容乃大 | 国产成人精品高清不卡在线 |