Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-如何将函数应用于每个表?_Jquery_Html_Html Table_Each - Fatal编程技术网

jQuery-如何将函数应用于每个表?

jQuery-如何将函数应用于每个表?,jquery,html,html-table,each,Jquery,Html,Html Table,Each,我制作了一个jQuery函数,用于创建分页系统 我的问题是,当我在包含多个表的页面中加载函数时,分页系统将应用于这两个表。我的意思是页数是两个表上的页数,而不是每个表的页数(对于每个div,有一个由PHP完成的表) 我试图修改我的代码,为div中的每个表应用函数,但它不起作用!以下是我的HTML代码: <div id="panneau"> <h3>Gestion des comptes</h3>

我制作了一个jQuery函数,用于创建分页系统

我的问题是,当我在包含多个表的页面中加载函数时,分页系统将应用于这两个表。我的意思是页数是两个表上的页数,而不是每个表的页数(对于每个
div
,有一个由PHP完成的表)

我试图修改我的代码,为div中的每个表应用函数,但它不起作用!以下是我的HTML代码:

<div id="panneau">
  <h3>Gestion des comptes</h3>                                  
   <table id ="tabUsers">
     <thead>
      <tr>
       <th>ID</th>
       <th>Pseudo</th>
       <th>An. naissance</th>
       <th>Région</th>
       <th>Email</th>
       <th>Téléphone</th>
       <th>Numéro masqué</th>
       <th>Date inscription</th>
       <th>Compte actif</th>
       <th>Actions</th>                         
      </tr>
     </thead>
     <tbody id = "corpsTab">
       <?php include_once 'includes/inc_consulterLesComptes.php'; ?>
     </tbody>                       
  </table>
</div>

<div id="panneauValidAnnonce">
  <h3>Gestion des annonces</h3>                                  
   <table id ="tabAnnonces">
     <thead>
      <tr>
       <th>ID</th>
       <th>Titre</th>
       <th>Description</th>
       <th>Date création</th>
       <th>Taille</th>
       <th>Couleur</th>
       <th>Marque</th>
       <th>Prix</th>
       <th>Annonceur</th>
       <th>Valide</th>                          
      </tr>
     </thead>
     <tbody id = "corpsTabAnnonces">
       <?php include_once 'includes/inc_ConsulterLesAnnonces.php'; ?>
     </tbody>                       
  </table>
</div>

指挥
身份证件
伪
一诞生
雷区
电子邮件
电话
努梅罗·马斯奎
日期铭文
完成活动
行动
安妮的手势
身份证件
乳头
描述
日期变更
泰尔
库勒
品牌
大奖赛
安诺切尔
手提包
有两个以上的表,但它们都有相同的格式

以下是我的jQuery函数:

$(document).ready(function() {
  //i've tried to add $.each('table').each(function()) but that doesnt work
  var rows=$('table').find('tbody tr').length;   
  var annonceParPage=3;             
  var nbrePage= Math.ceil(rows/annonceParPage);       
  var paginationId = $('table').attr('id');
  var $pagenumbers=$('<div id="'+paginationId+'Pages"></div>');

  for(i=0 ; i<nbrePage ; i++)   {
    $('<span class="page">'+(i+1)+'</span>').appendTo($pagenumbers);
  }

  $pagenumbers.insertAfter('table');

  $('.page').hover(function(){
    $(this).addClass('hover');
  }                                         
  function(){
    $(this).removeClass('hover');
  }
  );

  $('table').find('tbody tr').hide();               
  var tr=$('table tbody tr');
  for(var i=0;i<=annonceParPage-1;i++){
    $(tr[i]).show();
  }

  $('span').click(function(event){
    $('table').find('tbody tr').hide();
    for(i=($(this).text()-1)*annonceParPage ; i<=$(this).text()*annonceParPage-1 ; i++){
      $(tr[i]).show();
    }                                                                                   
  });        
});
$(文档).ready(函数(){
//我尝试添加$.each('table')。each(function()),但这不起作用
变量行=$('table').find('tbody tr').length;
var annonceParPage=3;
var nbrePage=Math.ceil(行/annonceParPage);
var paginationId=$('table').attr('id');
变量$PageNumber=$('');

对于(i=0;i类似的东西,我也做了一些优化:

$(document).ready(function() {
    $('table').each(function () {
      var thisTable = $(this);
      var rows=thisTable.find('tbody tr').length;   
      var annonceParPage=3;             
      var nbrePage= Math.ceil(rows/annonceParPage);       
      var paginationId = thisTable.attr('id');
      var $pagenumbers=$('<div id="'+paginationId+'Pages"></div>');

      for(i=0 ; i<nbrePage ; i++)   {
        $('<span class="page">'+(i+1)+'</span>').appendTo($pagenumbers);
      }

      $pagenumbers.insertAfter(thisTable);


      var tr=thisTable.find('tbody tr');
      tr.hide(); // optimised this selector

      for(var i=0;i<=annonceParPage-1;i++){
        $(tr[i]).show();
      }

      thisTable.find('span').click(function(event){
        thisTable.find('tbody tr').hide();
        for(i=($(this).text()-1)*annonceParPage ; i<=$(this).text()*annonceParPage-1 ; i++){
          $(tr[i]).show();
        }                                                                                   
      });        
    });
    $('.page').hover(function(){
        $(this).addClass('hover');
      },                                         
      function(){
        $(this).removeClass('hover');
    });
});
$(文档).ready(函数(){
$('table')。每个(函数(){
var thisTable=$(此);
var rows=thisTable.find('tbody tr').length;
var annonceParPage=3;
var nbrePage=Math.ceil(行/annonceParPage);
var paginationId=thisTable.attr('id');
变量$PageNumber=$('');

对于(i=0;IID应该是唯一的,使用类来代替或不同的Id对于$PageNumber是什么意思?这就是我试图做的:我获取表的Id并将其与“Pages”连接起来。这不一样吗?您有两个Id为tabUsersoh的表!我的错!第二个Id是:tabAnnonces