Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/07/2013, 14:03
Avatar de Reedyseth
Reedyseth
 
Fecha de Ingreso: enero-2009
Ubicación: Chihuahua, México
Mensajes: 419
Antigüedad: 15 años, 3 meses
Puntos: 36
Respuesta: Buscar y reemplazar un texto

Aquí esta el ejemplo:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6.         <title>
  7.             Ejercicio Remplazar
  8.         </title>
  9.         <style type="text/css">
  10.             body {font-family: Arial, Helvetica, sans-serif;}
  11.  
  12.         </style>
  13.         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  14.         <script type="text/javascript">
  15.         jQuery(document).ready(function($) {
  16.             setTimeout(function() {
  17.                 var ptext = $('p#p1').text();
  18.                 if (ptext == 'Texto Original') {
  19.                    $('p#p1').text('Texto remplazado.');
  20.                 }
  21.             },2000);
  22.  
  23.  
  24.             $('.btn').click(function() {
  25.                 var texto = $('input#txt1').val();
  26.                 $('p#p2').text(texto);
  27.             });
  28.         });
  29.  
  30.         </script>
  31.     </head>
  32.     <body>
  33.         <p id="p1">Texto Original</p>
  34.  
  35.         <input id="txt1" />
  36.         <button class='btn'>Remplazar</button>
  37.  
  38.         <p id="p2">Aquí se va a remplazar el texto del input cuando le des click.</p>
  39.  
  40.     </body>
  41. </html>

Saludos
__________________
Reedyseth
Te ayudo? No olvides dar un +
blog:http://behstant.com/blog
En el blog:Tutoriales de Desarrollo Web PHP, Javascript, BD y más.

Última edición por Reedyseth; 18/07/2013 a las 14:09