Guest User

Untitled

a guest
Feb 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <table style="width: auto;" id="tblEditavel" >
  2.  
  3. <th style=" text-align: center; width: 50px; ">Valor</th>
  4.  
  5. </tr>
  6.  
  7. <tr>
  8.  
  9. <td class="editavel" style="text-align: center; width: auto ; font-weight: bold;"> abc </td>
  10.  
  11.  
  12. </tr>
  13.  
  14. jQuery(function($) {
  15.  
  16.  
  17. $('#tblEditavel tbody tr td.editavel').dblclick(function(){
  18. //$('.editavel').dblclick(function(){
  19.  
  20. if($('td > input').length > 0){ // verifica se já existe algum input já na <td>
  21. return;
  22. }
  23.  
  24. console.log('teste');
  25.  
  26. var conteudoOriginal = $(this).text();
  27. var novoElemento = $("<input type='text' value='"+trim(conteudoOriginal)+"' class='campo_altera' />");
  28.  
  29. $(this).html(novoElemento.bind('blur keydown', function(e){
  30.  
  31. var keyCode = e.which;
  32. var conteudoNovo = $(this).val();
  33.  
  34. if(keyCode == 13 && conteudoNovo != '' && conteudoNovo != conteudoOriginal){
  35.  
  36. var objeto = $(this);
  37.  
  38. $.ajax({
  39. type:"POST",
  40. url:"assets/php/alterar_vt.php",
  41. data:{
  42.  
  43. valor_antigo:conteudoOriginal,
  44. valor_novo:conteudoNovo
  45.  
  46. },
  47. success:function(result){
  48. objeto.parent().html(conteudoNovo);
  49. $('body').append(result);
  50. }
  51. })
  52.  
  53.  
  54. }else if( keyCode == 27 || e.type == 'blur')
  55.  
  56. $(this).parent().html(conteudoOriginal);
  57. }));
  58.  
  59. $(this).children().select();
  60.  
  61. });
  62.  
  63.  
  64.  
  65.  
  66. });
Add Comment
Please, Sign In to add comment