<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script>
var count = 0;
$(document).ready(function(){
setInterval('contar()', 1000);
});
function contar(){
$("#tiempo").text(count++);
}
</script>
</head>
<body>
<div id="tiempo">0</div>
</body>
</html>
jueves, 21 de julio de 2011
javascript: contador setTimeout
miércoles, 13 de julio de 2011
javascript: Objetos y Colecciones en JavaScript
Hace mucho no posteaba nada.. bueno aca algo de lo que estuve viendo.
function Person(name,edad){
this.name = name;
this.edad = edad;
this.getEdad = function(){
return this.edad;
}
}
var juan = new Person("Juan Manuel", 15);
var ricardo = new Person("Ricardo Levano", 24);
var jorge = new Person("Jorge Adriano", 42);
// alert("hola me llamo" + juan.name + " y tengo " + juan.getEdad() + " años");
var amigos = [];
amigos.push(juan);
amigos.push(ricardo);
amigos.push(jorge);
// alert("tengo " + amigos.length + " amigos"); // 3
var amigosMayoresDeEdad = $.grep(amigos, function(per){
return per.edad > 18;
}); //necesito jQuery para el filter
alert("tengo " + amigosMayoresDeEdad.length + " amigos mayores de edad"); // 2
viernes, 15 de octubre de 2010
jQuery: Haciendo un Plugging en jQuery
<!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" dir="ltr"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Highlight jQuery plugin</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> // definición de la función $.fn.highlight = function(options){ // puede recibir un array de parámetros nombrados // invocamos a una función genérica que hace el merge // entre los recibidos y los de por defecto var opts = $.extend({}, $.fn.highlight.defaults, options); // para cada componente que puede contener el objeto jQuery que invoca a esta función this.each(function(){ // asignamos a la asignación del foco la invocación a una función $(this).focus(function(){ // que asigna al fondo el color recibido o el asginado por defecto $(this).css({"background" : opts.background}); }); // asignamos a la perdida del foco la invocación a una función $(this).blur(function(){ // que asigna al fondo un color blanco $(this).css({"background" : "white"}); }); }); }; // definimos los parámetros junto con los valores por defecto de la función $.fn.highlight.defaults = { // para el fondo un color por defecto background: '#a6cdec' }; </script> <script type="text/javascript"> $(document).ready(function(){ //$("form :input:visible").highlight(); $("form :input:visible").highlight({background: 'red'}); }); </script> </head> <body> <h1>Highlight jQuery plugin</h1> <form method="post" action="" name="test1"> <table> <tbody> <tr> <td> <label for="name">Name</label> </td> <td> <input id="name" type="text" /> </td> </tr> <tr> <td> <label for="country">Country</label> </td> <td> <input id="country" type="text" /> </td> </tr> <tr> <td> <label for="password">Password</label> </td> <td> <input id="password" type="password" /> </td> </tr> </tbody> </table> </form> <br /> <small>Mueve el foco entre los campos del formulario</small> </body> </html>
test rck:
http://jsfiddle.net/ric47121/rAbRG/
JavaScript: jSon
<script>
var Persona = {
'nombre': 'Ricardo',
'apellido': 'Levano',
'edad': '20'
};
Persona.getEdad = function() {
return this.edad;
}
Persona.saludar = function(fnCallBack) {
fnCallBack();
}
/**/
alert("hola soy " + Persona.nombre + " y tengo " + Persona.getEdad() + "años");
Persona.saludar(function(){
alert("holitass");
});
</script>
jueves, 7 de octubre de 2010
Linux: Buscar Cadena en Archivos
grep -lir "idbanner" *.php
O bien buscar emails
egrep -lir "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" *.php
O bien buscar emails
egrep -lir "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" *.php
l lista el nombre de archivos
i ignora mayusculas y minusculas
r recursivo
I:\intacto\Sonica\portal2010>grep -lir "idbanner" *.php
artistas_espacio_back.php
banners.php
index - copia.php
registro_usuariosOK.php
resultado_busqueda.php
shows_.php
viernes, 1 de octubre de 2010
jQuery: jSon
<script type="text/javascript">
$(document).ready(function () {
var query = "SELECT * FROM tbl_users WHERE user_id = 3";
$.getJSON("query_executor.php", { query: query}, function(data){
alert("user_name: " + data[0].user_name);
});
});
</script>
O
var html = $.ajax({
type: "GET",
url: "php_ajax/query_executor.php",
data: "query=" + query,
async: false
}).responseText;
var myObject = eval('(' + html + ')');
alert(var_dump_rck(myObject[0]));
El PHP
<?php
include("db.php");
$query = $_REQUEST['query'];
$result = mysql_query($query) or trigger_error(mysql_error());
$jsonArr = array();
while($row = mysql_fetch_object($result))
{
$jsonArr[] = $row;
}
echo json_encode($jsonArr);
?>
El Json Generado
[
{"user_id":"1","user_name":"pepe","user_fecha_nacimiento":"1986-09-01"},
{"user_id":"2","user_name":"juan","user_fecha_nacimiento":"1988-12-05"},
{"user_id":"3","user_name":"Ambrosio Romero","user_fecha_nacimiento":"1984-05-12"}
]
jueves, 16 de septiembre de 2010
jquery: var_dump
<script>
function var_dump_rck(data) {
var str = "";
$.each(data, function(key, value) {
//alert(key + ': ' + value);
str += key + ': ' + value + "\n";
});
return str;
}
</script>
Suscribirse a:
Entradas (Atom)