Created
December 12, 2010 22:26
-
-
Save ctroncoso/738404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="jquery-1.4.4.min.js" type="text/javascript"> </script> | |
<script> | |
var timer; | |
var myObj = { | |
count:0, | |
doSomething:function(){ | |
$("#printarea").prepend(this.count + " "); | |
}, | |
loopFunc:function(){ | |
this.doSomething(); | |
if (this.count == 100) return; | |
this.count++; | |
timer= setTimeout('myObj.loopFunc()',500); //mantenemos una referencia al timeout para poder detenerlo. | |
} | |
}; | |
// función para boton | |
function btn3(){ | |
var arr = $("#printarea").text().trim().split(" "); //obtiene texto, elimina espacios (cabeza y cola), y crea array a partir de espacios. | |
arr = $.grep(arr, function(n,i){ // grep devuelve solo elementos de un array que cumplan con una condición. | |
// n es el valor del elemento, i es el index. | |
return n%2 !=0; // valor de retono es TRUE, solo si modulo <> 0 (conserva los impares) | |
}); | |
$("#printarea").text(arr.join(" ")); // reemplaza el contenido de #printarea, con el texto del array unido con espacios. | |
} | |
// RESET GENERAL!!!!!!!! | |
function parentodo(){ | |
clearTimeout(timer); | |
myObj.count=0; | |
$("#printarea").text("<="); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Numbernator!</h1> | |
<h3 id="printarea"> -=- </h3> | |
<button onclick=myObj.loopFunc();>timeout recursivo</button> | |
<button onclick=parentodo();> detener </button> | |
<button onclick=btn3();>borrar pares</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment