可以在HTML元素被分配任意屬性?
例如:
<div imMakingUpAnAttribute="whatever"></div>
可以在HTML元素被分配任意屬性?
例如:
<div imMakingUpAnAttribute="whatever"></div>
是的,你可以自定義屬性..
<div imMakingUpAnAttribute="whatever"></div>
但你的HTML無法通過驗證。
爲了避免這個問題,只是你的前綴屬性與數據 -和你的HTML將被驗證......
<div data-imMakingUpAnAttribute="whatever"></div>
是。由John Resig的
HTML5自定義數據屬性後 http://ejohn.org/blog/html-5-data-attributes/
HTML4屬性 http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
是的,但它們必須data-
前綴。
自定義數據屬性是沒有命名空間的名字 開始以字符串「數據 - 」,有連字符 後至少一個字符,是XML兼容,幷包含在範圍內沒有字符屬性 U + 0041至U + 005A(拉丁文大寫字母A至拉丁文大寫字母Z)。
W3C HTML5規格:http://dev.w3.org/html5/spec/single-page.html?utm_source=dlvr.it&utm_medium=feed#embedding-custom-non-visible-data-with-the-data- * -attributes
下一個回答都有我有點擔心這個例子中,看到,根據它,規範禁止大寫字母 –
@Sushanth - 你的意思是「但你的HTML不會被驗證」?? –