秋天是沉甸甸的季节,秋天是收获的季节。秋天,写着收获,秋天,写着相思。秋天,比冬天更有生机勃勃的景象,白雪皑皑的冬天固然可爱,但是,瓜果飘香的金秋却更富有灿烂绚丽的色彩。
<html>
<head>
</head>
<body>
<style>
#x_edit{
height:320px;
width:540px;
border:1pxsolid#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>
<spanonclick="abc()">格式化</span>
<divcontentEditable="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><html><BR><head><BR></head><BR><body><BR><style><BR>#x_edit,#x_edit1{<BR>height:320px;<BR>width:540px;<BR>border:1pxsolid#666666;</P>
<P>color:red;</P>
<P>filter:chroma(color="#0f0f0f");<BR>background-color:#f0f0f0;<BR>font-family:verdana;<BR>font-size:11px;<BR>line-height:13px;<BR>margin-left:16px;<BR>overflow:scroll;<BR>border-left:none;<BR>scrollbar-arrow-color:#666666;<BR>scrollbar-base-color:#666666;<BR>scrollbar-darkshadow-color:#f0f0f0;<BR>scrollbar-face-color:#f0f0f0;<BR>}<BR></style><BR><spanonclick="abc()">试试获得selection的top,然后加上div的scrollTop,然后除以行高</span><BR><spanid="a"onclick="alert('a')">a</span><BR><spanid="b"onclick="alert('b')">b</span><BR><spanid="c"onclick="alert('c')"<BR>>c</span><BR><spanid="d"onclick="alert('d')">d</span><BR><spanid="e"onclick="alert('e')">e</span><BR><spanid="f"onclick="alert('f')">f</span<BR>><BR><spanid="g"<BR>onclick="alert('g')">g</span><BR><textareaid="x_edit"wrap=off></textarea><BR><divcontentEditable="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><BR><script><BR>functionabc(){<BR>//s=x_edit1.innerText;<BR>vars=x_edit.value;<BR>s=s.replace(/\n/gi,"");<BR>//s=s.replace(/<(\w+)(.*?)[^<>]>/gi,"<"+aaa("$1$2")+">");<BR>s=s.replace(/<(.*?)[^<>]>/gi,"<"+aaa("$1")+">");<BR>s=s.replace(/\n/gi,"@");<BR>//varLineValue=x_edit1.innerText.split("\r")<BR>/*varLineValue=x_edit.value.split("\r")<BR>for(vari=0;i<LineValue.length;i++){<BR>LineValue[i]=LineValue[i].replace(/(".*")/gi,"$1".replace(/</gi,"\xef").replace(/>/gi,"\xff"))<BR>LineValue[i]=LineValue[i].replace(/<(.*[^<>])>/gi,"<"+"$1"+">\r")<BR>LineValue[i]=LineValue[i].replace(/\r\r/gi,"\r")<BR>LineValue[i]=LineValue[i].replace(/(".*")/gi,"$1".replace(/\xef/gi,"<").replace(/\xff/gi,">"))<BR>}*/<BR>//x_edit1.innerText=LineValue.join("");<BR>//x_edit.value=LineValue.join("");<BR>x_edit.value=s;<BR>//x_edit1.innerText=s;<BR>}<BR>functionaaa(str){<BR>str=str.replace(/\r/gi,"");<BR>returnstr;<BR>}<BR></script><BR></body><BR></html></P>
</div> <script>
functionabc(){
vars=x_edit.innerText;
s=s.replace(/<\/?(\w+[\s\S]*?)>/gi,function(a){returna.replace(/[\r\n]/gi,"")});
x_edit.innerText=s;
}
</script>
</body>
</html>
本文用正则表达式格式化html标签的代码到此结束。时不时给自我一个能够沉默的理由来淡定人生。小编再次感谢大家对我们的支持!