用“/>”结束冷融合自闭合标签是一个好习惯吗?
在 HTML 中,我总是被教导用“/>”来结束自关闭。例如“
”、“”等。
但在 Coldfusion 中, ,从不关闭这些标签似乎是标准的。我经常看到这样的代码:
<cfset myVariable = someValue>
<cfset myOtherVariable = someOtherValue>
等等。
这是不好的代码,还是普遍接受的?我几乎在任何见过冷融合代码的地方都见过它。关闭这些标签有什么好处,还是保持原样就可以了?
In HTML, I was always taught to close self-closing with a "/>". For example "<br />
", "<input type='button' value='myButton' />
", etc.
In Coldfusion, though, it seems to be standard to just never close these tags. I'm constantly seeing code like:
<cfset myVariable = someValue>
<cfset myOtherVariable = someOtherValue>
etc.
Is this bad code, or is it commonly accepted? I've seen it almost anywhere that I've seen coldfusion code. Is there any benefit to closing these tags, or is it fine to leave it as it is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于 CFML 没有官方编码标准,因此是否使用这些标准取决于您。与使用大写/小写标签相同。
就我个人而言,我喜欢让我的代码美观且可读,所以我总是对单个标签使用这种语法。
但至少存在一个技术差异:自定义标签。让我通过例子来展示这一点。
考虑以下自定义标记:
现在这两种类型的调用:
这是输出:
第二种语法相当于
。可能还有更多差异,但我现在不记得有任何差异......:)
Because there's no official coding standard for CFML, it's up to you whether to use these. Same as using uppercase/lowercase tags.
Personally I love to have my code beautiful and readable, so I'm always using this syntax for single tags.
But there is at least one techincal difference: custom tags. Let me show this by example.
Consider following custom tag:
Now these two types of invokation:
And here's the output:
Second syntax is equivalent of
<cf_demo></cf_demo>
.Possibly there are more differences, but I can't remember any at this moment... :)
没关系,在html中也没有必要,除非是xhtml。
It doesnt matter, it is also not necessary in html unless it is xhtml.
我同意最后的评论。
我讨厌那些单一标签关闭。
这是毫无意义的,也不是 CFML 的编码标准。
当 xml 因其严格的标记语法而流行并且人们认为它对于 CFML 来说是正确的时,它就开始出现。 CFML 不是 HTML。像这样对待它本身实际上就是懒惰的编码。我还认为没有不必要的关闭它看起来更漂亮>> :)
但这就是我对你的看法。
我也不喜欢将 {} 扩展到每个括号的新行上。我想这只是个人喜好。
I agree with the last comment.
I hate those single tag closes.
It's pointless and not a coding standard for CFML.
It started appearing when xml became popular due to it's strict tag syntax and people assuming it was correct for CFML. CFML isn't HTML. Treating it as such is really in itself lazy coding. I also think it looks more beauiful without the unnecessary closing /> :)
but that's me for you.
I also dislike {} spread on to new lines for each bracket. I guess it's just personal preference.
我从来没有使用过 />;直到我开始使用 Dreamweaver CC 并且自动关闭仅在您以某种方式关闭标签时才起作用
I never used to use the /> until i started using Dreamweaver CC and the auto close only works if you close the tags somehow