Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/07/2012, 22:46
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Consulta con edición "en vivo"

Creo que construyendo los forms directamente para presentar las noticias te sería más sencillo
Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es-ar">
  3. <meta charset="utf-8" />
  4. <title>Html5</title>
  5.  
  6. <style type="text/css">
  7. /*<![CDATA[*/
  8.  
  9. input.noticias{
  10. width: 400px;
  11. border: none;
  12. margin-bottom: 5px;
  13. font-weight: bold;
  14. font-size: 14pt;
  15. }
  16. textarea.noticias{
  17. width: 400px;
  18. height: 70px;
  19. border: none;
  20. margin-bottom: 5px;
  21. }
  22.  
  23. /*]]>*/
  24. <script type="text/javascript">
  25. //<![CDATA[
  26. function editar(noti){
  27. var idnoticia = noti.split('_');
  28. var tit = 'titulo'+idnoticia[1];
  29. var cont = 'contenido'+idnoticia[1];
  30. var bot = 'botones'+idnoticia[1];
  31. var tit_original = document.getElementById(tit).value;
  32. var cont_original = document.getElementById(cont).value;
  33. document.getElementById(tit).readOnly = false;
  34. document.getElementById(tit).style.backgroundColor = '#9DC864';
  35. document.getElementById(cont).readOnly = false;
  36. document.getElementById(cont).style.backgroundColor = '#73C567';
  37. document.getElementById(cont).style.overflow = 'auto';
  38. document.getElementById(bot).style.display = 'inline-block';
  39. }
  40. //]]>
  41. </head>
  42.  
  43. <h1>Noticias</h1>
  44. <div id="contenedor_noticias">
  45. <form action="#">
  46. <input class="noticias" type="text" name="titulo" id="titulo1" readonly="readonly" value="Título Noticia 1"><br />
  47. <textarea cols="10" rows="10" class="noticias" style="overflow: hidden;" name="contenido" id="contenido1" readonly="readonly">Contenido noticia 1</textarea><br />
  48. <input type="button" onclick="editar('noticia_1')" value="Editar" /> <span id="botones1" style="display: none;">
  49. <input type="button" onclick="cancelar('noticia_1')" value="Cancelar" />
  50. <input type="button" onclick="guardar('noticia_1')" value="Guardar" /> </span>
  51. <input type="button" onclick="eliminar('noticia_1')" value="Eliminar" />
  52. </form>
  53. </div>
  54. </body>
  55. </html>

Para cancelar, guardar, eliminar, utilizás ajax
cancelar:
recuperás el texto original y lo pones en el titulo y contenido correspondiente al id de la noticia
guardar: guardás en la base de datos y restableces el readonly y ocultás los botones
Eliminar: borrás de la base de datos y le hacés innerHTML = ""; al contenedor individual de la noticia

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.