栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > 正则表达

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

正则表达 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

复制代码 代码如下:





#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;
  }

格式化

<html>
<head>
</head>
<body>
<style>
#x_edit,#x_edit1{
  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()">试试获得selection的top,然后加上div的scrollTop,然后除以行高</span>
<span id="a" onclick="alert('a')">a</span>
<span id="b" onclick="alert('b')">b</span>
<span id="c" onclick="alert('c')"
>c</span>
<span id="d" onclick="alert('d')">d</span>
<span id="e" onclick="alert('e')">e</span>
<span id="f" onclick="alert('f')">f</span
>
<span id="g"
 onclick="alert('g')">g</span>
<textarea id="x_edit" wrap=off></textarea>
<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'></div>
<script>
function abc(){
    //s=x_edit1.innerText;
    var s=x_edit.value;
    s=s.replace(/n/gi,"");
    //s=s.replace(/<(w+)(.*?)[^<>]>/gi,"<"+aaa("$1$2")+">");
    s=s.replace(/<(.*?)[^<>]>/gi,"<"+aaa("$1")+">");
    s=s.replace(/n/gi,"@");
    //var Linevalue=x_edit1.innerText.split("r")
    
    //x_edit1.innerText=Linevalue.join("");
    //x_edit.value=Linevalue.join("");
    x_edit.value=s;
    //x_edit1.innerText=s;
}
function aaa(str){
    str=str.replace(/r/gi," ");
    return str;
}
</script>
</body>
</html>







转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/60884.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号