The PRE element tells visual user agents that the enclosed text is "preformatted". When handling preformatted text, visual user agents: * May leave white space intact. * May render text with a fixed-pitch font. * May disable automatic word wrap. * Must not disable bidirectional processing.
"preformatted". When handling preformatted text, visual user agents: * May leave white space intact.
* May render text with a fixed-pitch font.
* May disable automatic word wrap.
* Must not disable bidirectional processing.
最重要的,第三条:禁止自动换行。这个是可以理解的。
但是,我加入 以后,是可以换行的。你试试?
<pre>abc def</pre>
但是,如果innerHTML它,就没有效果。
如果innerText它,就把它原封不动显示出来了。不能理解为什么innerHTML的时候会没有效果……
pid.outerHTML=pid.outerHTML.replace(pid.innerHTML,strResult)
abc abc abc abc abc abc abc abc abc
</pre>
<script>
var strVar=pid.innerText;
var a=10; //定义每行字数
var strResult="";
for(i=0;i<=strVar.length-1;i=i+a)
{
var strTemp=strVar.substr(i,a)+" ";
strResult+=strTemp;
}
pid.outerHTML=pid.outerHTML.replace(pid.innerHTML,strResult)
</script>
这样?实验成功!厉害!————是怎么想到这样做的?