Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/02/2012, 19:44
Avatar de chicohot20
chicohot20
 
Fecha de Ingreso: mayo-2009
Mensajes: 388
Antigüedad: 15 años
Puntos: 43
Respuesta: varios forms mismo js

Código HTML:
Ver original
  1. <!DOCTYPE HTML>
  2. <title>Hola</title>
  3. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  4. <script type="text/javascript">
  5. $(function(){
  6.     $("#new").click(function(){ newform() });
  7.     $("#mascota form").submit(function(){
  8.         alert($(this).serialize());
  9.         return false;
  10.     })
  11. })
  12. function newform() {
  13.     var div = document.createElement("div");
  14.     div.innerHTML = document.getElementById("mascota").innerHTML;
  15.     document.getElementById("new_mascota").appendChild(div);
  16.     $("form",div).submit(function(){
  17.         alert($(this).serialize());
  18.         return false;
  19.     })
  20. }
  21. form{border: 1px solid #555; width: 300px; padding: 8px;}
  22. #mascota{padding: 8px; background: #DDD;}
  23. #new_mascota{padding: 8px; background: #AAA;}
  24. h4{margin: 0px;}
  25. </head>
  26. <button id="new">New Form</button>
  27. <div id="mascota">
  28.     <h4>Mascota</h4>
  29.     <form action=""><input type="text" name="text"/><input type="submit" value="Enviar"/></form>
  30. </div>
  31. <div id="new_mascota">
  32.     <h4>New Mascota</h4>
  33. </div>
  34. </div>
  35. </body>
  36. </html>