我正在使用 jQuery 将 CSS 文件的内容 .load() 到 div 中。但是当加载该文件的内容时,所有换行符、制表符等都消失了。有没有办法在保留换行符的同时加载 css 文件?
提前致谢!
最佳答案
而不是 <div>
只需使用 <pre>
element要保留格式,您可以 .load()
以完全相同的方式进入它。
HTML 的默认行为是不显示换行符、额外空格等(<pre></pre>
除外)、from the HTML4 spec :
For all HTML elements except
PRE
, sequences of white space separate "words" (we use the term "word" here to mean "sequences of non-white space characters"). When formatting text, user agents should identify these words and lay them out according to the conventions of the particular written language (script) and target medium.
关于jquery - 通过 jQuery 在 CSS 代码 .load()ed 中看不到换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277930/