HTML属性名称中允许使用哪些字符? [英] What characters are allowed in an HTML attribute name?

查看:122
本文介绍了HTML属性名称中允许使用哪些字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML属性 name = value 对中,'name'部分允许使用的字符是什么? .....看看一些常见属性,看起来像只有字母(AZ和AZ)被使用,但是还有什么其他的字符可以被允许?...可能是数字(0-9),连字符( - )和句点(。)...是否有任何规范?

In HTML attribute name=value pairs, what are the characters allowed for the 'name' portion? ..... Looking at some common attributes it appears that only letters (a-z and A-Z) are used, but what other chars could be allowed as well?... maybe digits (0-9), hyphens (-), and periods (.) ... is there any spec for this?

推荐答案

这取决于允许的含义。每个标签都有一个固定的属性名称列表,这些属性名称是有效的,并且在html中它们不区分大小写。在一个重要的意义上,只有这些正确顺序的字符才是允许的。

It depends what you mean by "allowed". Each tag has a fixed list of attribute names which are valid, and in html they are case insensitive. In one important sense, only these characters in the correct sequence are "allowed".

查看它的另一种方式是浏览器将哪些字符视为有效的属性名称。这里最好的建议来自HTML 5的解析器规范,它可以在这里找到: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Another way of looking at it, is what characters will browsers treat as a valid attribute name. The best advice here comes from the parser spec of HTML 5, which can be found here: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

它表示除tab以外的所有字符,换行符,换页符,空格,立体,大于符号,引号,撇号和等号都将被视为属性名称的一部分。就个人而言,我不会尝试推动这个边缘案例。

It says that all characters except tab, line feed, form feed, space, solidus, greater than sign, quotation mark, apostrophe and equals sign will be treated as part of the attribute name. Personally, I wouldn't attempt pushing the edge cases of this though.

这篇关于HTML属性名称中允许使用哪些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆