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\" />
开发者

Double quotes in html non-literals? Which is the correct one: type="checkbox" or type=checkbox?

开发者 https://www.devze.com 2023-01-23 20:57 出处:网络
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\

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.

0

精彩评论

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