html是一門優(yōu)美的語(yǔ)言,完美的縮進(jìn),統(tǒng)一的格式。打開(kāi)所有的網(wǎng)頁(yè),查看源文件,都會(huì)發(fā)現(xiàn)開(kāi)頭規(guī)規(guī)矩矩地寫著
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
</code>
當(dāng)然這個(gè)標(biāo)準(zhǔn)是1999年12月24日完善的最后版本(W3C獻(xiàn)給大家的圣誕節(jié)大禮?),到今天也是十周年了。于是,他的繼任者出現(xiàn)了,也就是HTML5。
引述Mr Hunt的原話,HTML 5 introduces and enhances a wide range of features including form controls, APIs, multimedia, structure, and semantics.
結(jié)構(gòu)
首先介紹structure也就是結(jié)構(gòu)的改變。下面是一個(gè)最典型的div頁(yè)面。
從圖中可以看出,為了區(qū)分這些div,使用了大量的id,class來(lái)表示他們,而且命名也經(jīng)常讓我很頭疼(笑,小白。。)。HTML5將div細(xì)分了類型,如下:
在我看來(lái),這個(gè)改變只是名稱上的變化,能略微提高編寫效率而已。而下面的兩個(gè)改變,會(huì)引發(fā)整個(gè)互聯(lián)網(wǎng)行業(yè)的變革。
視頻/音頻
HTML5中加入了<video><audio>標(biāo)簽,這樣,就可以像引入圖片一樣,引入視頻或者音頻文件(不知道他能不能支持flv,不過(guò)按照YouTube現(xiàn)在這個(gè)人氣....),代碼如下:
<code>
<video poster="poster.jpg">
<source src="video.3gp" type="video/3gpp" media="handheld">
<source src="video.ogv" type="video/ogg; codecs=theora, vorbis">
<source src="video.mp4" type="video/mp4">
</video>
<audio>
<source src="music.oga" type="audio/ogg">
<source src="music.mp3" type="audio/mpeg">
</audio>
</code>
提供了source 元素,讓瀏覽器根據(jù)媒體類型或編碼器的支持來(lái)指定視頻或音頻文件。當(dāng)然也可以在其中加入已經(jīng)很廣泛使用的JS控制,比如onclick="video.pause();之類。
我想,有了<Video><audio>標(biāo)簽,各家播放器廠商做的插件應(yīng)該就沒(méi)有市場(chǎng)了吧,想想那些亂七八糟的新浪視頻差價(jià)、ccav視頻插件(各種惡心插件,還帶毒) 你一定會(huì)愛(ài)上HTML5的。
datagrid
最令我振奮的改變,也是他讓我愛(ài)上HTML5。Document Object Model(DOM)中增加了 HTMLDataGridElement
接口以支持這個(gè)元素,如下
<code>
interface HTMLDataGridElement : HTMLElement {
attribute DataGridDataProvider data;
readonly attribute DataGridSelection selection;
attribute boolean multiple;
attribute boolean disabled;
void updateEverything();
void updateRowsChanged(in RowSpecification row, in unsigned long count);
void updateRowsInserted(in RowSpecification row, in unsigned long count);
void updateRowsRemoved(in RowSpecification row, in unsigned long count);
void updateRowChanged(in RowSpecification row);
void updateColumnChanged(in unsigned long column);
void updateCellChanged(in RowSpecification row, in unsigned long column);
};
</code>
想想,你可以控制每一行每一列的數(shù)據(jù)綁定,也就沒(méi)有了聯(lián)合查詢的必要?。?!
把兩個(gè)對(duì)象的屬性糅雜在一個(gè)Model里面,真是一件無(wú)法忍受的事情,HTML5!YOU MADE IT.
另外,HTML5在input元素的type中增加了datetime, datetime-local, date, month, week, time, number, range, email, url,輸入日期就不需要各種JS組件了吧,數(shù)字, email和url也不需要再寫js去較驗(yàn)正確性了。
現(xiàn)在我下一個(gè)時(shí)間選擇的JS,估計(jì)也得好幾十行代碼了。那些討厭的正確性驗(yàn)證,也讓瀏覽器自己玩去吧,我只管存到數(shù)據(jù)庫(kù)就是了,吼吼。
最后,我想引述Elliotte Harold 的結(jié)束語(yǔ)
HTML 5 is part of the future of the Web. Its new elements enable clearer, simpler markup that makes pages more obvious. Div
and span
still have their places, but those places are much more restricted than they used to be. Many pages will no longer need to use them.
Although not all browsers will support these new elements at first, the same has been true for most elements introduced after HTML was first invented: img
, table
, object
, and many more. Support will come with time. In the meantime, HTML's must-ignore behavior for unrecognized elements means that users with legacy browsers will still be able to read HTML 5 pages. They can do so today. Users with more modern browsers will get an enhanced experience, but no one will be left out.
Eight years is a long time to wait for new features, especially in the fast-moving world of the Web. HTML 5 restores some of the excitement of the early days when Netscape, Microsoft, and others were introducing new elements every other week. At the same time, it takes a much more careful approach to defining these elements so that everyone can use them interoperably. The future looks bright.
想想吧,這個(gè)還在孕育的標(biāo)準(zhǔn),如果我們。。能夠參與進(jìn)去,哇唔,it's a wonderful imagination, and as Mr Harold said ,no one will be left out....
如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇