佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > 用正則表達(dá)式格式化html標(biāo)簽的代碼

用正則表達(dá)式格式化html標(biāo)簽的代碼

熱門標(biāo)簽:電子圍欄 阿里云 銀行業(yè)務(wù) 團(tuán)購網(wǎng)站 Linux服務(wù)器 Mysql連接數(shù)設(shè)置 服務(wù)器配置 科大訊飛語音識(shí)別系統(tǒng)
復(fù)制代碼 代碼如下:

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;htmlgt;BR>lt;headgt;BR>lt;/headgt;BR>lt;bodygt;BR>lt;stylegt;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;/stylegt;BR>lt;span onclick="abc()"gt;試試獲得selection的top,然后加上div的scrollTop,然后除以行高lt;/spangt;BR>lt;span id="a" onclick="alert('a')"gt;alt;/spangt;BR>lt;span id="b" onclick="alert('b')"gt;blt;/spangt;BR>lt;span id="c" onclick="alert('c')"BR>gt;clt;/spangt;BR>lt;span id="d" onclick="alert('d')"gt;dlt;/spangt;BR>lt;span id="e" onclick="alert('e')"gt;elt;/spangt;BR>lt;span id="f" onclick="alert('f')"gt;flt;/spanBR>gt;BR>lt;span id="g"BR>nbsp;onclick="alert('g')"gt;glt;/spangt;BR>lt;textarea id="x_edit" wrap=offgt;lt;/textareagt;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;/divgt;BR>lt;scriptgt;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;ilt;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;/scriptgt;BR>lt;/bodygt;BR>lt;/htmlgt;/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標(biāo)簽、屬性等正則表達(dá)式匯總
  • asp自動(dòng)補(bǔ)全html標(biāo)簽自動(dòng)閉合(正則表達(dá)式)
  • asp.net正則表達(dá)式刪除指定的HTML標(biāo)簽的代碼
  • Java/Js下使用正則表達(dá)式匹配嵌套Html標(biāo)簽
  • 移除HTML標(biāo)簽的正則表達(dá)式
  • 請(qǐng)教一個(gè)正則表達(dá)式,匹配所有Html標(biāo)簽外部的指定字符串
  • 使用正則表達(dá)式去除所有html標(biāo)簽只保留文字

標(biāo)簽:大理 衡水 萍鄉(xiāng) 蚌埠 棗莊 衢州 江蘇 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《用正則表達(dá)式格式化html標(biāo)簽的代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    吴桥县| 澄迈县| 东乌珠穆沁旗| 托克托县| 临安市| 右玉县| 郴州市| 大荔县| 保康县| 宝丰县| 平乡县| 平阴县| 寻乌县| 和田市| 搜索| 松潘县| 清水河县| 大新县| 罗江县| 宜城市| 萝北县| 靖安县| 西林县| 临洮县| 吴旗县| 富蕴县| 伊金霍洛旗| 宜兰县| 宁夏| 安国市| 徐汇区| 邻水| 海门市| 神农架林区| 泾源县| 滕州市| 西华县| 寻甸| 泸定县| 法库县| 屯门区|