Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/08/2011, 16:57
Avatar de IsaBelM
IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 11 meses
Puntos: 1012
Respuesta: chrome toma como definida variable no definida

gracias por interesaros

estoy totalmente de acuerdo con vosotros. typeof() debería devolver "undefined" y luego "number", pero devuelve "object" y luego "number"

laratik, la versión es la misma que la tuya

os he montado un pequeño ejemplo por si al caso no me hice entender
Cita:
<!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 content="text/html; http-equiv="Content-Type" charset=utf-8"/>
<title></title>
<script type="text/javascript">
function fnc() {
alert('el tipo es ' +typeof(estado))
if (typeof(estado) == "undefined" || estado == 0) {
estado = 1;
}else{
estado = 0;
}
}

function fnc2() {
alert(estado);
}

function escucha() {
if(document.getElementById('evento').addEventListe ner) {
document.getElementById('evento').addEventListener ('click', fnc, false);
document.getElementById('estado').addEventListener ('click', fnc2, false);
} else {
document.getElementById('evento').attachEvent('onc lick', fnc);
document.getElementById('estado').attachEvent('onc lick', fnc2);
}
}

window.onload = function() {escucha()};
</script>
</head>
<body>
<h3>al pulsar el botón evento y luego el otro devuelve 1. al hacer el mismo proceso otra vez devolverá 0</h3>
<form>
<input type="button" id="evento" value="evento" />
<input type="button" id="estado" value="está activo el botón evento?" />
</form>
</body>
</html>

Última edición por IsaBelM; 15/01/2016 a las 06:47 Razón: eliminar la corrección para continuar con el flujo del tema