2009-01-20 14:36 | Posted by Sunshow | Filed Under WebDev
其实题目不太确切,应该是对回车(Return,即r)换行(New line,即n)的不同处理
看示例就明白了:
<!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 1 line 2 line 3 line 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的部分参考上一篇文章
Permalink | Trackback
Click here to cancel reply.
Name
Email
Website
请输入验证码
Comment
Recent Comments