在HTML id属性中,冒号是什么意思?

时间:2021-02-05 03:35:52

I have seen an HTML code like this for the ID attribute:

我曾见过ID属性的HTML代码:

id="t1:c3"

Can someone explain this to me? What is the purpose of the colon (:)?

有人能给我解释一下吗?冒号的目的是什么?

Thank you.

谢谢你!

3 个解决方案

#1


25  

Colons are allowed inside ID attributes, but hold no special significance. It's not really advisable to use them because they can sometimes cause problems, such as when used with jQuery or CSS, where the colon has special meaning as a pseudo-selector.

在ID属性中允许冒号,但没有特殊意义。使用它们并不明智,因为它们有时会导致问题,比如在使用jQuery或CSS时,冒号作为伪选择器具有特殊意义。

#2


3  

If the HTML is generated with Java ServerFaces this usually produces such IDs, i.e. if the form has the ID form1 and the element has the ID firstName this results in an ID form1:firstName if the element is on top level, if there are several ones created in a loop they look like form1:1:firstName, form1:2:firstName, …

如果HTML生成与Java ServerFaces这通常会产生这样的ID,即如果表单的ID form1和元素的ID firstName这导致一个ID form1:firstName如果在顶层元素,如果有几个中创建一个循环的样子form1:1:firstName,form1:2:firstName,……

This framework behaviour cannot be changed.

这种框架行为是不能改变的。

#3


1  

In addition to the above I have discovered that Omniture uses colons to help define classes related to the layout.

除了上述之外,我还发现Omniture使用冒号来帮助定义与布局相关的类。

#1


25  

Colons are allowed inside ID attributes, but hold no special significance. It's not really advisable to use them because they can sometimes cause problems, such as when used with jQuery or CSS, where the colon has special meaning as a pseudo-selector.

在ID属性中允许冒号,但没有特殊意义。使用它们并不明智,因为它们有时会导致问题,比如在使用jQuery或CSS时,冒号作为伪选择器具有特殊意义。

#2


3  

If the HTML is generated with Java ServerFaces this usually produces such IDs, i.e. if the form has the ID form1 and the element has the ID firstName this results in an ID form1:firstName if the element is on top level, if there are several ones created in a loop they look like form1:1:firstName, form1:2:firstName, …

如果HTML生成与Java ServerFaces这通常会产生这样的ID,即如果表单的ID form1和元素的ID firstName这导致一个ID form1:firstName如果在顶层元素,如果有几个中创建一个循环的样子form1:1:firstName,form1:2:firstName,……

This framework behaviour cannot be changed.

这种框架行为是不能改变的。

#3


1  

In addition to the above I have discovered that Omniture uses colons to help define classes related to the layout.

除了上述之外,我还发现Omniture使用冒号来帮助定义与布局相关的类。