Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

html - valid order for attributes of input type tag

I know it's very basic question and hope not so important, but i want to know the answer, please don't suggest only refer links.

we all daily face <input> type tag and their attributes (type, class, id, value, name, size, maxlength, tabindex etc..), I just want to know

  • is there any specific order required for attributes in <input> tag or can we use any order?
  • if there an order then what is it?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Already been answered, but my full and expanded answer is:

  • There is no predefined order for the attributes in terms of passing w3c validation... it's completely up to you.

However, you should introduce your own standard and stick to it.

If there are multiple coders working on the application they should all stick to the same standard.

If you are a team leader, web-dev business owner, manager, etc, it is your responsibility to encourage (and enforce) a culture that uses this standard.

When doing code reviews the attribute order should be checked, and anything that fails you should make the coder responsible fix it up... they'll only muck it up once or twice if they know they'll have to rewrite their code!!!

And why all this fuss and bother over attribute order?

  • This will increase code development and debugging speed.
  • It makes code more readable
  • It encourages the coders (or you) to pay attention to the little details
  • It helps to fosters an environment of "accountability for your own code"

My personal preference is:

  1. type (so you can instantly see what it is)
  2. id
  3. class (I like to keep 2 and 3 together as they are the most common js/jQuery selectors)
  4. name
  5. value (I like to keep 4 and 5 next to each other so you can quickly reference what input it is and it's value).
  6. All others (like checked, max-size, etc)
  7. style
  8. tabindex (I like 7 and 8 to be at the end as it's "non-relevant", in terms of the actual functionality, they are more styling/usability stuff, keep 'em out of the way!

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...