用“/>”结束冷融合自闭合标签是一个好习惯吗?

发布于 2024-12-06 12:13:14 字数 358 浏览 1 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凉城 2024-12-13 12:13:14

由于 CFML 没有官方编码标准,因此是否使用这些标准取决于您。与使用大写/小写标签相同。

就我个人而言,我喜欢让我的代码美观且可读,所以我总是对单个标签使用这种语法。

但至少存在一个技术差异:自定义标签。让我通过例子来展示这一点。

考虑以下自定义标记:

<cfif thisTag.ExecutionMode EQ "start">
    started<br/>
</cfif>

running<br/>

<cfif thisTag.ExecutionMode EQ "end">
    ended<br/>
</cfif>

现在这两种类型的调用:

<p><cf_demo></p>

<cf_demo>

<p><cf_demo /></p>

<cf_demo />

这是输出:

<cf_demo>
started
running

<cf_demo />
started
running
running
ended

第二种语法相当于

可能还有更多差异,但我现在不记得有任何差异......:)

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:

<cfif thisTag.ExecutionMode EQ "start">
    started<br/>
</cfif>

running<br/>

<cfif thisTag.ExecutionMode EQ "end">
    ended<br/>
</cfif>

Now these two types of invokation:

<p><cf_demo></p>

<cf_demo>

<p><cf_demo /></p>

<cf_demo />

And here's the output:

<cf_demo>
started
running

<cf_demo />
started
running
running
ended

Second syntax is equivalent of <cf_demo></cf_demo>.

Possibly there are more differences, but I can't remember any at this moment... :)

鸠魁 2024-12-13 12:13:14

没关系,在html中也没有必要,除非是xhtml。

It doesnt matter, it is also not necessary in html unless it is xhtml.

一曲琵琶半遮面シ 2024-12-13 12:13:14

我同意最后的评论。

我讨厌那些单一标签关闭。

这是毫无意义的,也不是 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.

翻了热茶 2024-12-13 12:13:14

我从来没有使用过 />;直到我开始使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文