html elements 添加自定义属性 attributes/properties...
时间:2010-08-07 来源:baoeni
以前一直怀疑是不是所有的HTML elements都能随便的添加自定义属性,因为印象中好像有些是不行的,今天做了一个实验,发现所有浏览器(包括IE)好像都可以添加自定义属性,包括表单和表格,估计我以前遇到的是某些elments的某些属性只读吧。
以下适用于所有浏览器:
<div customizedAtt="customedAtt"></div>
document.getElementById('target').customizedProperty = 'bla';
console.info(document.getElementById('target').customizedProperty);
document.getElementById('target').customizedProperty = 'bla2';
console.info(document.getElementById('target').customizedProperty);
相关阅读 更多 +