Can I use white spaces in the name attribute of an HTML element? [duplicate]
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.
精彩评论