Tag Archives: javascript

Javascript no intrusivo

Forma de usar Javascript fuera del flujo HTML:

1
2
3
4
5
6
7
8
9
10
11
12
<head>
  <script type="text/javascript">
    window.onload = function() {
      var reloj = document.getElementById("reloj");
      var fecha = (new Date()).toLocaleString();
      reloj.innerHTML = fecha;
    }
  </script>
</head>
<body>
  <div id="reloj">No te puedo mostrar la hora</div>
</body>

Tags: , ,

Documentación oficial de Prototype

Finalmente, los desarrolladores del famoso framework de JavaScript crearon un sitio con su documentación:
http://prototypejs.org/api

También existe una sección de tutoriales y tips.

Otro buen tutorial: Developer Notes for prototype.js

Tags: ,

Función capitalize

Función capitalize en JavaScript, creada por Jonas Raoni Soares Silva. He cambiado la regex original/\w+/gpor/\S+/gpara que funcione con acentos.

1
2
3
4
5
6
7
8
9
myText = "hElLo wORlD";

String.prototype.capitalize = function() {
    return this.replace(/\S+/g, function(a) {
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};

document.write( myText.capitalize() );

Tags: , ,