HTML 5 - 尽可能早期采用 - 好还是坏? [英] HTML 5 - Early Adoption Where Possible - Good or Bad?

查看:86
本文介绍了HTML 5 - 尽可能早期采用 - 好还是坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题的灵感来自这个问题,其中最常用的回答建议使用HTML 5中的功能。对我来说这似乎是一个很好的方法,但它让我很好奇使用来自未来规格的功能。



HTML 5提供了许多不错的改进,其中许多可以使用,而不会导致当前浏览器的问题。



一些示例:

  // new,simple HTML5 doctype将浏览器置于标准模式)
<!doctype HTML>

//新的输入类型,方便,通用的客户端验证
< input type =emailname =emailAddress/>
< input type =numbername =userid/>
< input type =datename =dateOfBirth/>

// newrequired属性表示需要一个字段
< input type =textname =userNamerequired =true/>

// new'data-'前缀属性
//在动态页面中轻松插入js-accessible元数据
< div data-price =33.23>
<! - - >
< / div>
< button data-item-id =93024>添加项< / button>

许多新功能旨在使浏览器能够自动验证表单,给他们更好的输入(例如日期选择器)。有些只是方便,似乎是一个好的方式,为未来做好准备。



他们目前不打破任何东西(就我所知)在当前浏览器并且它们允许使用干净,通用的客户端代码。



但是,即使它们在HTML 5中都有效,但它们对HTML 4无效,HTML 5仍然



这是早期使用这些功能的好主意吗?

有没有我没有意识到的浏览器实现问题?



我们现在应该开发利用HTML 5草图特征的网页吗?

解决方案

有几件事要考虑:


  1. 首先,验证并不意味着多少,因为HTML页面非常有效,但撰写不当,无法访问等。请参见 no 更改为有效的HTML图标将XHTML作为文本/ html认为有害(参考另一个回应中提及的hobo-web测试)

  2. 因此,我强烈建议您使用新的DOCTYPE:在HTML5中使用它的唯一原因是它是最小的事情,触发标准模式在浏览器,所以如果你想要标准模式,去与它;您几乎没有理由使用另一个,冗长,容易出错的DOCTYPE

  3. 对于表单增强功能,您可以使用Weston Ruter的 webforms2 JS库将其带到无意识的浏览器

  4. 最后,关于 data - * 属性,它a)在所有浏览器中工作(只要使用 getAttribute()),b)比滥用 title class 属性和c)不会打扰你验证,因为我们前面说过验证isn非常重要(当然是,但是如果有效性错误是有意的,则您的网页无效并且您可以在W3C验证程序中使用HTML5验证,因此...) 。);因此没有真正理由不使用它们。


This question was inspired a bit by this question, in which the most upvoted answer recommended using a feature from HTML 5. It certainly seemed to be a good method to me, but it made me curious about using features from a future spec in general.

HTML 5 offers a lot of nice improvements, many of which can be used without causing problems in current browsers.

Some examples:

// new, simple HTML5 doctype (puts browsers in standards mode)
<!doctype HTML>

// new input types,  for easy, generic client side validation
<input type="email" name="emailAddress"/>
<input type="number" name="userid"/>
<input type="date" name="dateOfBirth"/>

// new "required" attribute indicates that a field is required
<input type="text" name="userName" required="true"/>

// new 'data-' prefixed attributes
// for easy insertion of js-accessible metadata in dynamic pages
<div data-price="33.23"> 
    <!-- -->
</div>
<button data-item-id="93024">Add Item</button>

Many of these new features are designed to make it possible for browsers to automatically validate forms, as well as give them better inputs (for example a date picker). Some are just convenient and seem like a good way to get ready for the future.

They currently don't break anything (as far as I can tell) in current browsers and they allow for clean, generic clientside code.

However, even though they are all valid in HTML 5, they are NOT valid for HTML 4, and HTML 5 is still a draft at this point.

Is it a good idea to go ahead and use these features early?

Are there browser implementation issues with them that I haven't realized?

Should we be developing web pages now that make use of HTML 5 draft features?

解决方案

There are several things to consider:

  1. First, validation doesn't mean that much, because an HTML page can very well be valid but badly authored, inaccessible, etc. See Say no to "Valid HTML" icons and Sending XHTML as text/html Considered Harmful (in reference to the hobo-web tests mentioned in another response)
  2. Given this, I'd highly recommend using the new DOCTYPE: the only reason for having it in HTML5 is that it's the smallest thing that triggers standards mode in browsers, so if you want standards mode, go with it; you have little to no reason to use another, verbose, error-prone DOCTYPE
  3. As for the forms enhancements, you can use Weston Ruter's webforms2 JS library to bring it to non-aware browsers
  4. and finally, about the data-* attributes, it a) works in all browsers (as long as you use getAttribute()), b) is still better than abusing the title or class attributes and c) won't bother you with validation as we said earlier that validation isn't that important (of course it is, but it doesn't matter that your page is invalid if the validity errors are willful; and you can already use HTML5 validation in the W3C validator, so...); so there's no real reason not to use them either.

这篇关于HTML 5 - 尽可能早期采用 - 好还是坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆