par
jojolapine » 10 janv. 2007, 16:52
bon alors j'ai avancé un peu... et j'ai réussit à faire des trucs assez cool
voici un code qui marche sous firefox:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>youyou</title>
<script type="text/javascript" language="javascript">
HTMLElement.prototype.__defineGetter__(
"enfants",
function() {
var arr = new Array(), i = 0, l = this.childNodes.length;
for ( i = 0; i < l; i++ ) {
if ( this.childNodes[ i ].nodeType == 1 ) {
arr.push( this.childNodes[ i ] );
}
}
return arr;
}
);
HTMLElement.prototype.__defineGetter__(
"contenu",
function() {
return this.childNodes[0].nodeValue;
}
);
HTMLElement.prototype.__defineGetter__(
"parent",
function() {
return this.parentNode;
}
);
</script>
</head>
<body>
<table>
<tr style="cursor: pointer;" onclick="if(this.enfants[1].contenu=='li 2') alert('ok'); else alert('pas ok');">
<td>bonjour</td>
<td>li 2</td>
<td>ouhgogh</td>
</tr>
<tr>
<td style="cursor: pointer;" onclick="if(this.parent.enfants[1].contenu=='li 2') alert('ok'); else alert('pas ok');">bonjour</td>
<td>li 2</td>
<td>ouhgogh</td>
</tr>
</table>
</body>
</html>
tout les alert affichent OK!
bon maintenant, j'ai essayer de redéfinir childNodes pour ie, mais sans succès, en fait j'ai essayer dans l'esprit qqch comme ça:
if(ie){
HTMLElement.prototype.__defineGetter__(
"enfants",
childNodes
);
pour simplement changer le nom du prototype, mais ça ne fonctionne pas...
comment faire pour simplement changer le nom du prototype ?
bon alors j'ai avancé un peu... et j'ai réussit à faire des trucs assez cool :P
voici un code qui marche sous firefox:[php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>youyou</title>
<script type="text/javascript" language="javascript">
HTMLElement.prototype.__defineGetter__(
"enfants",
function() {
var arr = new Array(), i = 0, l = this.childNodes.length;
for ( i = 0; i < l; i++ ) {
if ( this.childNodes[ i ].nodeType == 1 ) {
arr.push( this.childNodes[ i ] );
}
}
return arr;
}
);
HTMLElement.prototype.__defineGetter__(
"contenu",
function() {
return this.childNodes[0].nodeValue;
}
);
HTMLElement.prototype.__defineGetter__(
"parent",
function() {
return this.parentNode;
}
);
</script>
</head>
<body>
<table>
<tr style="cursor: pointer;" onclick="if(this.enfants[1].contenu=='li 2') alert('ok'); else alert('pas ok');">
<td>bonjour</td>
<td>li 2</td>
<td>ouhgogh</td>
</tr>
<tr>
<td style="cursor: pointer;" onclick="if(this.parent.enfants[1].contenu=='li 2') alert('ok'); else alert('pas ok');">bonjour</td>
<td>li 2</td>
<td>ouhgogh</td>
</tr>
</table>
</body>
</html>[/php]
tout les alert affichent OK!
bon maintenant, j'ai essayer de redéfinir childNodes pour ie, mais sans succès, en fait j'ai essayer dans l'esprit qqch comme ça:
[php]if(ie){
HTMLElement.prototype.__defineGetter__(
"enfants",
childNodes
);[/php]
pour simplement changer le nom du prototype, mais ça ne fonctionne pas... :(
comment faire pour simplement changer le nom du prototype ?