1

这是分页的简单代码。并在两个选项卡中用于两个不同的表。

<script>
  $(".clik_for_fetch").click(function(){
      var request={ id: $(this).attr('fetch_id') };
      $.ajax({
                url:"pro/userlist.php",
                data:request,
                dataType:"html",
                type:'POST', 
                beforeSend: function(){
                },
                success:function(result){
                      $("#MyId tbody ").html(result);
                 },
                complete: function(){
                }
        });
    });
</script>

如何获取 ID 以动态显示此行

$("#MyId tbody ").html(result);
var request={ id: $(this).attr('fetch_id') };

HTML 代码:tab1

<table class="table table-striped" id="usertable">
</table>

和号码包

<li><a href="#" class="clik_for_fetch" fetch_id1="'.$i.'">'.$i.'</a></li>'

选项卡2

<table class="table table-striped" id="grouptable"
</table>

和号码包

<li><a href="#" class="clik_for_fetch" fetch_id2="'.$i.'">'.$i.'</a></li>'

编辑:这是 HTML 代码

    <div class="bs-example bs-example-tabs">
      <ul id="myTab" class="nav nav-tabs">
        <li class="active"><a href="#userslist" data-toggle="tab" > userlist </a></li>
        <li><a href="#usergroups" data-toggle="tab">  usergroups </a></li>
      </ul>
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade in active" id="userslist">
              <table class="table table-striped" id="usertable">
                  <thead>
                    <tr>
                      <th> ID </th>
                      <th> name </th>
                      <th> username </th>
                      <th style="width: 36px;"> edit </th>
                    </tr>
                  </thead>
                  <tbody>


                  </tbody>
             </table>
        </div>


<hr>
     <ul class="pagination" id="pagination">
        <?php
            while($total_rows_user > 0)
            {

                echo '<li><a href="#" class="clik_for_fetch" fetch_id1="'.$i.'">'.$i.'</a></li>';
                $i++;
                $total_rows_user--;

            }
        ?>

     </ul>

            </div>

        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade in " id="usergroup">
              <table class="table table-striped" id="grouptable">
                  <thead>
                    <tr>
                      <th> ID </th>
                      <th> name </th>
                      <th> username </th>
                      <th style="width: 36px;"> edit </th>
                    </tr>
                  </thead>
                  <tbody>


                  </tbody>
             </table>
        </div>


<hr>
     <ul class="pagination" id="pagination">
        <?php
            while($total_rows_group > 0)
            {

               echo '<li><a href="#" class="clik_for_fetch" fetch_id2="'.$i.'">'.$i.'</a></li>';
                $i++;
                $total_rows_group--;

            }
        ?>

     </ul>

        </div>
    </div><!--End tab-->
  <script>
      $(".clik_for_fetch").click(function(){
          var request={ id: $(this).attr('fetch_id') };
          $.ajax({
                    url:"pro/userlist.php",
                    data:request,
                    dataType:"html",
                    type:'POST', 
                    beforeSend: function(){
                    },
                    success:function(result){
                          $("#MyId tbody ").html(result);
                     },
                    complete: function(){
                    }
            });
        });
  </script> 

代码由两个不同选项卡中的两个表组成,见下

每个表都有一个单独的 id 以及页数

4

3 回答 3

3

尝试这个

    $("body").delegate(".clik_for_fetch", "click", function() {
                   var request={ id: $(this).attr('data-id') };
              //    var request={ id: $(this).data('id') };  //you could also use this
              $.ajax({
                    url:"pro/userlist.php",
                    data:request,
                    dataType:"html",
                    type:'POST', 
                    beforeSend: function(){
                    },
                    success:function(result){
                          $("#MyId tbody ").html(result);
                     },
                    complete: function(){
                    }
            });
        });

你的html代码

'<li><a href="#" class="clik_for_fetch" data-id="'.$i.'">'.$i.'</a></li>'
于 2013-10-04T07:53:53.847 回答
0

使用此代码:

HTML 代码:

<li><a href="#" class="clik_for_fetch" data-id="'.$i.'" >'.$i.'</a></li>'

id 的 Jquery 代码:

var request={ id: $(this).attr("data-id") };
于 2013-10-04T07:15:19.423 回答
0

我会从点击事件中获取属性,但首先我会平等地命名它们,没有数字,比如fetch_id

$(".clik_for_fetch").click(function(obj){
var attr = $(obj).attr("fetch_id");
});
于 2013-10-04T07:12:25.370 回答