readAttribute

readAttribute(element, attribute) -> String | null

返回 elemnet 由参数 attribute 指定的属性值,若不存在指定的属性值,返回 null

提供这个方法主要是基于以下两个目的:首先,它对 getAttribute 做了简单的封装,在 Safari 和 Internet Explorer 下,getAttribute 并不是一个“真正”的函数对象(它没有 .apply.call 实例方法)。 其次,它清理了 Internet Explorer 处理属性时造成的可怕的混乱。

样例

<a id="tag" href="/tags/prototype" rel="tag" title="view related bookmarks." my_widget="some info.">Prototype</a> 
$('tag').readAttribute('href'); 
// -> '/tags/prototype'
$('tag').readAttribute('title'); 
// -> 'view related bookmarks.' 
$('tag').readAttribute('my_widget');
// -> 'some info.'