, , , , IE7, , , ( ajax - ), .
, , - getElementsByTagName getElementById, , , .
, - :
if (!window.Element || !window.Element.prototype || !window.Element.prototype.hasAttribute) {
(function (document) {
var originalGetElementById = document.getElementById;
var originalGetElementsByTagName = document.getElementsByTagName;
function hasAttribute (attrName) {
return typeof this[attrName] !== 'undefined';
}
function attachFunction (element) {
if (element && !element.hasAttribute) {
element.hasAttribute = hasAttribute;
}
return element;
}
document.getElementById = function (elementId) {
var element = originalGetElementById(elementId);
return attachFunction(element);
}
document.originalGetElementsByTagName = function (tagName) {
var elements = originalGetElementsByTagName(tagName);
for(var i = 0, len = elements.length; i < len; i++) {
attachFunction(element[i]);
}
return elements;
}
}(document));
}
javascript, IE:
document.getElementsByTagName document.getElementById.
var inputs = document.getElementsByTagName('input');
document.write(
'has?' + inputs[0].hasAttribute('abc')
);
document.write(
'has?' + inputs[0].hasAttribute('data-abc')
);