Foros del Web » Programando para Internet » Javascript »

FireFox e IExplorer: ¿Jerarquías con implementaciones diferentes?

Estas en el tema de FireFox e IExplorer: ¿Jerarquías con implementaciones diferentes? en el foro de Javascript en Foros del Web. consideren el siguiente código: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento sin t&iacute;tulo</title> <script language="javascript1.3"> function estiraEncoje() { obj = document.forma.texto; if(obj.size>10) { obj.size=10; ...
  #1 (permalink)  
Antiguo 04/05/2006, 09:28
 
Fecha de Ingreso: mayo-2006
Mensajes: 3
Antigüedad: 18 años, 10 meses
Puntos: 0
Pregunta FireFox e IExplorer: ¿Jerarquías con implementaciones diferentes?

consideren el siguiente código:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<script language="javascript1.3">
function estiraEncoje()
{
obj = document.forma.texto;
if(obj.size>10)
{
obj.size=10;
}
else
{
obj.size=20;
}

}
function genera()
{
var newE = document.createElement('input');
newE.type = "button";
newE.name = "bt";
newE.value = "tocame";
newE.onclick = estiraEncoje;
document.forma.appendChild(newE);
}
function destruye()
{
buttons = document.forma.childNodes;
if (buttons.length>1)
{
toDelete = buttons[1];
document.forma.removeChild(toDelete);
}
}
function imprime()
{
childs = document.forma.childNodes;
texto = "";
for(i=0; i<childs.length; i++)
{
texto = texto + " " + childs[i].nodeType;
}
document.write(texto);
}
</script>
</head>

<body>
<input type="button" name="genera" onclick="genera()" value="generador">
<input type="button" name="destruye" onclick="destruye()" value="destructor">
<input type="button" name="imprime" onclick="imprime()" value="impreime hijos de forma">

<form name="forma" >
<input type="text" name="texto" value="como que no?" onclick="estiraEncoje(document.getElementById('tex to'));"></form>
</body>
</html>


Este código funciona de manera diferente en Firefox que en IE. Una vez pulsado el boton "generador" se crea un nuevo botón "tocame". Pero al pulsar "destructor" Firefox borra el input mientras IE borra el botón tócame. ¿Acaso la jerarquía de nodos no es la misma en ambos navegadores?¿Qué diferencia es la qué provoca el cambio en el comportamiento?
  #2 (permalink)  
Antiguo 04/05/2006, 09:44
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 23 años, 1 mes
Puntos: 772
Hola matrixer

Firefox interpreta como un nodo el salto de línea que tienes en el form:

<form name="forma" >
<input type="text" name="texto"...

Creo que lo más sencillo es que cambies un poco la función de destruir:

function destruye()
{
buttons = document.forma.elements;
if (buttons.length>1)

Espero que te sirva. Saludos,
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:47.