• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    用正则表达式格式化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;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标签、属性等正则表达式汇总
    • asp自动补全html标签自动闭合(正则表达式)
    • asp.net正则表达式删除指定的HTML标签的代码
    • Java/Js下使用正则表达式匹配嵌套Html标签
    • 移除HTML标签的正则表达式
    • 请教一个正则表达式,匹配所有Html标签外部的指定字符串
    • 使用正则表达式去除所有html标签只保留文字
    上一篇:js中2005-05-02怎么转换为2005/5/2?
    下一篇:php利用正则表达式取出图片的URL
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

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