gruss Felix,
Hat man zwei verschiedene HTML - Elemente, von denen das eine ein
name-Attribut (z.B. name="wert") und ein anderes ein ID-Attribut
mit jeweils demselben Inhalt hat (also id="wert"), dann liefert
document.getElementById("wert")
nicht unbedingt wie gewünscht das
Element mit der passenden ID, sondern fälschlicherweise das HTML-
Element mit einem passenden Wert im name-Attribut, das im Dokument
an vorausgehender Stelle notiert ist.
Gibt es dazu sichere Workarounds? ...
keine ahnung, man koennte sich aber einen ebensolchen bauen.
wie ueblich der hinweis auf die [http://jconsole.com], in die
der folgende code zur machbarkeitdemonstration hineinkopiert
und ausgefuehrt werden sollte:
// [Array.generics.iterators.accessors] - [http://www.pseliger.de/jsExtendedApi/jsApi.Array.mozGenerics.dev.js] september 23-2006:
Array.filter = function (obj, fct) {var arr=[];if(typeof fct=="function"){var i,l=(((obj instanceof Array)||((typeof obj.length=="number")&&((typeof obj.item=="function")||(typeof obj.item=="object")||(typeof obj.item=="string")||(obj instanceof window.NodeList)||(obj instanceof window.HTMLCollection))))?(obj.length):(obj.length||0));for(i=0;i<l;++i){if(fct.call(null,(obj[i]||obj.item(i)),i,obj)){arr.push(obj[i]||obj.item(i));}}}return arr;};
(function () {
var sh = (window || this); // sh : scripting host.
var dc = sh.document; // dc : document.
//var LNL = dc.getElementsByTagName("*"); // create a *live node list*.
//print("LNL.length : " + LNL.length);
//sh.HTMLCollection = (((typeof sh.HTMLCollection != "function") && ((typeof sh.HTMLCollection != "object") || !sh.HTMLCollection))?( { } ):(sh.HTMLCollection));
sh.NodeList = (((typeof sh.NodeList!="function")&&((typeof sh.NodeList!="object")||!sh.NodeList))?({}):(sh.NodeList));
sh.Node = (((typeof sh.Node!="function")&&((typeof sh.Node!="object")||!sh.Node))?({}):(sh.Node));
dc.getElementById = (function (coreFctById) {
return (function (str) {
str = String(str);
//return coreFctById(str);
//print("LNL.length : " + LNL.length);
//return Array.filter((LNL || document.getElementsByTagName("*")), (function (elm) {
return Array.filter(document.getElementsByTagName("*"), (function (elm) {
return (elm && (typeof elm.id == "string") && (elm.id == str));
}))[0];
});
})(dc.getElementById);
delete sh;
delete dc;
delete arguments.callee;
})();
print("document.getElementById : " + document.getElementById);
var myElm = document.getElementById("output");
print("myElm.id : " + myElm.id);
viel erfolg - peterS. - pseliger@gmx.net
--
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]