so I have this...
< input type="checkbox" id="chvre" value="1"/>
Here, it makes sense that the id
value is in quotes, as it would be a string identifier. But what about the type
value? Isn't checkbox
a type, like String and Boolean? Why do I keep seeing these supposedly non-literals between double quotes? Is it bad practice? What should I aim at getting used to doing?
Furthermore, what if I want the value of value (that "1") to be a number instead of being treated as a string? If I read that value in javascript, var val = document.getElementById("chvre").value
I have to use the parseInt()
thingy.
So, what's the right way of doing these things? Do I just d开发者_运维知识库ouble quote everything? Should I not?
When using attributes, you must remember the rules of XML, as well as the rules of general attribute use.
These are as follows:
- Attributes must occur within the opening tag of an element. The close tag is merely a place marker and should have nothing else between the brackets except the slash and tag name.
- All attribute names must be in lower case.
- All attributes must have a value.
- All attribute values must be in double quotes. Remember that a double quote and two single quotes are not the same thing.
- All attributes must be included in a space separated list, with no other characters between them.
More Info:
- http://www.daaq.net/old/xhtml/index.php?page=xhtml+attributes
HTML and XML have no conception of string vs. non-string literals. (They're markup languages, not normal languages)
Double-quotes are optional in HTML, but there is no semantic difference type=checkbox
and type="checkbox"
.
All attribute values should be in double-quotes.
精彩评论