Ver Mensaje Individual
  #4 (permalink)  
Antiguo 23/03/2013, 18:20
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Usar getElementById() como valor de un miembro de un Array

Declará la función dentro del objeto

Código:
<!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>
<title>titulo</title> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<style type="text/css">
/*<![CDATA[*/

#cuadro1{
left: 30px;
top: 50px;
position: absolute;
width: 300px;
height: 300px;
background: lime;
}

/*]]>*/
</style>
<script type="text/javascript">
//<![CDATA[

function cuadro(cadena) {
var cuadro1		=	document.getElementById(cadena);
var top			=	document.defaultView.getComputedStyle(cuadro1, '').getPropertyValue('top');
var left		=	document.defaultView.getComputedStyle(cuadro1, '').getPropertyValue('left');
var width		=	document.defaultView.getComputedStyle(cuadro1, '').getPropertyValue('width');
var height		=	document.defaultView.getComputedStyle(cuadro1, '').getPropertyValue('height');	
this.muestraX = function () { return limiteX*2; };					
var limiteX= parseInt(top)+parseInt(height);
var limiteY= parseInt(left)+parseInt(width);
						
console.log(limiteX); //<-----Aqui va bien. Se  muestra el valor
}

window.onload = function(){
//cuadro('cuadro1');
var casilla = new cuadro("cuadro1");
console.log(casilla.muestraX());
}

//]]>
</script>
</head>
<body>
<div  id="cuadro1"></div>
</body>
</html>
Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.