开发者

Can I use white spaces in the name attribute of an HTML element? [duplicate]

This question already has answers here: What characters are allowed in the HTML Name attribute inside input tag? (5 answers) Closed 8 years ago.

A question has rised in my project team as we are designing a web page. Can we use white characters (like space) in the name attribute of an HTML element ? eg. <input type="che开发者_Go百科ckbox" name="first check box">

My concern is mainly the behavior of different browsers with such an attribute value.

We are now in the design phase, until we get to write some code and test this, a long time will pass, so I am asking you experts about this.

Thank you !


Yes.

The name attribute contains CDATA. It can be more or less anything you like. (You shouldn't include leading or tailing white space because user agents can ignore it, but white space in the middle is fine).

Note that name attributes do not have NAME tokens as their data type (although the id attribute does (the id attribute doesn't take an ID token)), so you don't have the restrictions imposed on NAME tokens.


Most browsers will handle this fine, as long as they are properly quoted. However, for sake of eliminating corner cases, it's much wiser to user CamelCase and avoid the probability of browsers not handling it correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜