function comprobarLong(text, LONGMAXIMA) {
var body;
if (text.length > LONGMAXIMA)
{
body = text.substring(0, LONGMAXIMA - 2);
body += "..";
return body;
}
else
{
return text;
}
}
miércoles, 10 de agosto de 2011
javascript: comprobarLong
javascript: Array de objetos
var Hostels = {
"selectedHostels" : []
}
Hostels.isHostel = function(id) {
for (i = 0; i < this.selectedHostels.length; i++) {
if (this.selectedHostels[i].Id == id) return true;
}
return false;
}
Hostels.addHostel = function(id) {
var hotel = { "Id": id }
if (this.isHostel(id)) {
this.selectedHostels.pop(hotel);
}
else {
this.selectedHostels.push(hotel);
}
console.log(this.selectedHostels);
}
miércoles, 3 de agosto de 2011
jquery: levantar template con jquery
$.ajax({
url: "../templates/hotel.htm",
cache: false,
success: function(html) {
//$(".listado_hoteles").append(html);
var imprimir = "";
for (var i = 1; i <= 4; i++) {
imprimir = html.replace("@@NRO@@", i);
$(".listado_hoteles").append(imprimir);
}
}
jueves, 21 de julio de 2011
javascript: contador setTimeout
<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>
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>
Suscribirse a:
Entradas (Atom)