2017-02-05 59 views
0

追加行我已經使用工具提示上表數據等工具提示不工作後在表的jquery

enter image description here

和代碼

<tr> 
      <td class="text-center"><%=i %></td> 
      <td class="text"><span rel="tooltip" title="<%=client.getName() %>"><%=client.getName() %></span></td> 
      <td class="text"><span rel="tooltip" title="<%=client.getContactPerson() %>"><%=client.getContactPerson() %></span></td> 
      <td class="text"><span rel="tooltip" title="<%=client.getContactNumber() %>"><%=client.getContactNumber() %></span></td> 
      <td class="text"><span rel="tooltip" title="<%=client.getEmail() %>"><%=client.getEmail() %></span></td> 
      <td class="text"><span rel="tooltip" title="<%=client.getAddress() %>"><%=client.getAddress() %></span></td> 
      <td class="text"><span rel="tooltip" title="<%=client.getDepartment() %>"><%=client.getDepartment() %></span></td> 
      <td class="td-actions text-right"> 
</tr> 

上分頁我正在通過jquery的填充數據,但添加行後,上述工具提示不起作用,這裏是我的javascript代碼

clients.forEach(function(client){ 
        $("#paginationTable tbody").append("<tr>"+ 
        "<td class=\"text-center\">"+(i+1)+"</td>"+ 
        "<td class=\"text\"><span rel=\"tooltip\" title=\""+client.name+"\""+">"+client.name+"</span></td>"+ 
        "<td class=\"text\"><span rel=\"tooltip\" title=\""+client.contactPerson+"\""+">"+client.contactPerson+"</span></td>"+ 
        "<td class=\"text\"><span rel=\"tooltip\" title=\""+client.contactNumber+"\""+">"+client.contactNumber+"</span></td>"+ 
        "<td class=\"text\"><span rel=\"tooltip\" title=\""+client.email+"\""+">"+client.email+"</span></td>"+ 
        "<td class=\"text\"><span rel=\"tooltip\" title=\""+client.address+"\""+">"+client.address+"</span></td>"+ 
        "<td class=\"text\"><span rel=\"tooltip\" title=\""+client.department+"\""+">"+client.department+"</span></td>"+ 
        "<td class=\"td-actions text-right\">"+ 
          "<button type=\"button\" rel=\"tooltip\" title=\"View Profile\" class=\"btn btn-info btn-simple btn-xs\">"+ 
          "<i class=\"fa fa-user\"></i>"+ 
         "</button>"+ 
         "<button type=\"button\" rel=\"tooltip\" title=\"Edit Profile\" class=\"btn btn-success btn-simple btn-xs\">"+ 
          "<i class=\"fa fa-edit\"></i>"+ 
         "</button>"+ 
         "<button type=\"button\" rel=\"tooltip\" title=\"Remove\" class=\"btn btn-danger btn-simple btn-xs\">"+ 
          "<i class=\"fa fa-times\"></i>"+ 
         "</button>"+ 
        "</td>"+ 
       "</tr>"); 
+0

這是因爲它沒有事件偵聽器,因爲它是動態創建的。檢查這[**鏈接**](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements)它可能會有所幫助! –

+0

可能重複[Event binding on dynamic created elements?](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) –

+0

可能是重複的。我需要實施。確切的解決方案 –

回答

0

該解決方案用於提升工具提示。

$('body').on('mouseenter', '.tableContent', function() { 
if ($(this).attr('data-toggle') == 'tooltip') 
{ 
    $(this).tooltip({ 
     container: 'body', 
     placement: 'left', 
     trigger: 'hover' 
    }).tooltip('show'); 
} 

});

說明

當鼠標懸停在你的元素進行檢查,是否該數據切換已被添加到,如果它沒有被添加.tooltip()函數被調用添加數據切換和還會調用工具提示('show')以在第一次懸停時實際顯示該項目。