IE和Firefox对换行的不同处理 发表于 2009-01-20 | 分类于 WebDev 其实题目不太确切,应该是对回车(Return,即r)换行(New line,即n)的不同处理 看示例就明白了:123456789101112131415161718192021222324252627282930313233<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><script type="text/javascript"><!--function removeLineBreaksIE() { var testDiv = document.getElementById('test'); var text = testDiv.innerHTML; testDiv.innerHTML = '<pre>' + text.replace(/rn/ig, '') + '</pre>';}function removeLineBreaksFx() { var testDiv = document.getElementById('test'); var text = testDiv.innerHTML; testDiv.innerHTML = text.replace(/n/ig, '');}//--></script></head><body><div id="test"><pre>line 1line 2line 3line 4</pre></div><button type="button" onclick="removeLineBreaksIE();">Remove line breaks for IE!</button><button type="button" onclick="removeLineBreaksFx();">Remove line breaks for Firefox!</button></body></html> 其中pre的部分参考上一篇文章