dongyuan1984 2013-09-07 08:18
浏览 58
已采纳

我想通过点击编辑选择整行进行编辑

Here, I can see box only on one element, the one I selected for edition. I want to see box on all the elements when I click on edit. How can I deal with this?

Here is my code...

<!DOCTYPE html>
<html>
       <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
            <script>
            function mDown(obj) {
                obj.innerHTML="update"
            }

            function mUp(obj) {
                obj.innerHTML="update"
            }

            jQuery(document).ready(function(){
                jQuery("form").submit(function(){
                //alert("Submitted");
                jQuery("#myform").submit();
                });  
            $('.edit').click(function(){  
        //alert("Submitted");
            $('.ajax').html($('.ajax input').val());  
            $('.ajax').removeClass('ajax');  

            $(this).addClass('ajax');  
            $(this).html('<input id="editbox" size="'+  
            $(this).text().length+'" value="' +  
            $(this).text() + '" type="text">');  

            $('#editbox').focus();                                                  
        });  
        $('.edit').keydown(function(event){ 
                     // alert("Submitted");
         arr = $(this).attr('class').split( " " );  
         if(event.which == 13) {   
             $.ajax({    
                             type: "POST",  
             url:"config.php",  
             data: "value="+$('.ajax input').val()+"&rownum="+arr[2]+"&field="+arr[1],  
             success: function(data){  
                 $('.ajax').html($('.ajax input').val());  
                 $('.ajax').removeClass('ajax');                                                     
              }});  
          }                                             
          });  
          $('#editbox').live('blur',function(){

          $('.ajax').html($('.ajax input').val());  
          $('.ajax').removeClass('ajax');  
    }); 

    $('td.delete1').on('click',function() {
        //alert("Submitted");
        var parent = $(this).closest('tr');
        $.ajax({            
        type: 'get',
        url: 'dl.php', // <- replace this with your url here
        data: 'ajax=1&delete=' + $(this).attr('id'),
        beforeSend: function() {
            parent.animate({'backgroundColor':'#fb6c6c'},300);
        },
        success: function() {
            parent.fadeOut(300,function() {
                parent.remove();
            });
        }
        });   
        $('.delete').confirm({
         msg:'Do you really want to delete this?',
         timeout:3000
        });         
       });
   });
  • 写回答

1条回答 默认 最新

  • dongqiao8502 2013-09-07 08:45
    关注

    Your $(this) will hold the only element on which, you have clicked.
    So,

    $(this).addClass('ajax');  
    $(this).html('<input id="editbox" size="'+  
    $(this).text().length+'" value="' +  
    $(this).text() + '" type="text">');
    

    this code will add textbox to only that element.

    You need to take parent of clicked element first, like

    var p = $(this).parentNode; 
    

    and then take all child nodes for 'p' element.
    And use for loop for all child elements and add above code for each single element, not for $(this).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类