本文介绍了白色空间,标签中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 什么规则处理带有尾随空格的属性值,或带有嵌入换行符的标签或 属性值?示例如下:HREF带有 嵌入式换行符,SRC带有尾随空格,IMG标签分布在 多行。 < a href ="我自己 "> < img src =" /images/picture.gif" width =" 80" height =" 65" alt ="什么,我担心?">< / a> 解决方案 属性之间的空白区域(包括换行符)并不重要, 尽可能多地使用它 - 我经常使用它来保持线条简短。 关于属性值中的空格:HTML规范说 用户代理可能会忽略CDATA 属性值中的前导和尾随空格。 < http://www.w3.org/TR/REC-html40/types.html#h-6.2> 我没有详细测试过这个,但我认为最多浏览器确实剥离了 的空白区域 - 我已经看到各种网站都有这样的链接,似乎 工作。但你不应该依赖它,一些UA可能不会这样做并且遇到一个 断开的链接。 - Benjamin Niemann 电子邮件:粉红色at odahoda dot de WWW: http://pink.odahoda.de/ < span id = foo onclick =" alert(''不要\ 忘记& nbsp;包含&#x5C; 这个'')">点击我< / span> 来自维也纳的Csaba Gabor Harlan Messinger写道: 空格字符(空格,制表符,换页符,新行)并不重要 并由解析器折叠到单个空格(除非在< pre> block)。 这是所有UA(包括Amaya)的HTML规则。 你可能想看相反,在* tag 之间的换行符和空格*因为在某些不同的实现中它会导致 DOM树中的幻象节点。 What rules deal with attribute values with trailing spaces, or tags orattribute values with embedded newlines? Examples below: the HREF withembedded newline, the SRC with trailing spaces, and IMG tag spread overmultiple lines.<a href="myself.html"><img src="/images/picture.gif " width="80"height="65"alt="What, me worry?"></a> 解决方案White space (including linebreaks) between attributes is not significant,use it as much as you like - I use this often to keep lines short.Regarding white space in attribute values: the HTML Spec saysUser agents may ignore leading and trailing white space in CDATAattribute values.<http://www.w3.org/TR/REC-html40/types.html#h-6.2>I have not tested this in detail, but I think that most browsers do stripthe white space - I have seen various sites with such links and it seems towork. But you should not rely on it, some UAs may not do it and encounter abroken link.--Benjamin NiemannEmail: pink at odahoda dot deWWW: http://pink.odahoda.de/<span id=foo onclick="alert(''Don\''t \forget to include \this'')">Click me</span>Csaba Gabor from ViennaSpace characters (space, tab, form feed, new line) are not significantand being collapsed to a single space by parser (unless in <pre>block).This is HTML rule equal for all UA''s (including Amaya).You may want to watch instead line breaks and spaces *between* tagbecause on some surrent implementations it leads to phantom nodes inDOM Tree. 这篇关于白色空间,标签中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-12 12:09