使用jQuery的动态表格单元格

时间:2017-07-19 18:17:02

标签: jquery dynamic html-table

此代码有问题。我已经工作了很多个小时,看不出有什么问题。当我从建议列表中选择一个名称时,所有表格单元格都选择了相同的名称。 有什么诀窍?

<td title="Workers">  

//// The input for the table cell ////

   <input type="text" name="workername" 
id="workername-<?php echo $rs['taskid']; ?>" 
class="workername-<?php echo $rs['taskid']; ?>"
placeholder="Enter a Name" value="<?php echo $rs['username'];?>"
   /> 

//// Suggestion list under the input value ////


 <div class="suggestionlist<?php echo $rs['taskid']; ?>">
 </div>  


//// The script to get input and show the suggestion list under input   ////    

   <script>  
 $(document).ready(function(){  
   $('.workername-<?php echo $rs['taskid']; ?>').keyup(function(){  
   var query = $(this).val();  
        if(query != ''){  
            $.ajax({  
            url:"searchallworkersfromdatabase.php",  
            method:"POST",  
            data:{query:query},  
            success:function(data) { 

           $('.suggestionlist<?php echo $rs['taskid']; ?>').fadeIn();  
           $('.suggestionlist<?php echo $rs['taskid']; ?>').html(data);  
        }  
            });  
    }  
 });  
     $(document).on('click', 'li', function(){  
     $('.workername-<?php echo $rs['taskid']; ?>').val($(this).text());  
     $('.suggestionlist<?php echo $rs['taskid']; ?>').fadeOut();  
         });  
             }); 
   </script> 
</td>

0 个答案:

没有答案