mysql的PHP生成的表:不与tablesorter的工作 [英] Mysql PHP generated table: doesn't work with Tablesorter

查看:110
本文介绍了mysql的PHP生成的表:不与tablesorter的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个伟大的tablesorter插件的jQuery但我不能让我的PHP生成的表工作。这里的code:

 <脚本类型=文/ JavaScript的>


    函数表(){

        $(#容器)的负载(table.php randval =?+的Math.random())。

    }


    $(文件)。就绪(函数(){

        表();
        $(表)的tablesorter()。
   });

< / SCRIPT>
 

其中#container的是在div所在的表将和表是表的名称。我得到的表加载,但排序功能无法正常工作。

它的工作原理,如果我直接在HTML页面中把表..但我没有看到这一点具有静态表进行排序。

任何帮助将是非常美联社preciated。

解决方案

$。load()的执行异步请求,即函数不等待数据返回之前到达。因此 $(表)的tablesorter(); 执行最有可能之前表添加到文档中。要么使之同步调用或(甚至更好)传递的处理程序完整的事件来加载。

http://api.jquery.com/load/

.load(URL,[数据],[完成(responseText的,textStatus,XMLHtt prequest))
网址 数据的地图或字符串被发送到服务器的请求。
完整(responseText的,textStatus,XMLHtt prequest)的请求完成时执行的回调函数。

 <脚本类型=文/ JavaScript的>
  $(文件)。就绪(函数(){
    $(#集装箱)。载荷(
      table.php?randval =+的Math.random(),
      空值,
      功能(responseText的,textStatus,REQ){
        $(表)的tablesorter()。
      }
    );
  });
< / SCRIPT>
 

I found this great Tablesorter plugin for jQuery but I can't make it work with my PHP generated table. Here's the code:

<script type="text/javascript">


    function table() {

        $("#container").load("table.php?randval="+Math.random());

    }


    $(document).ready(function() { 

        table();
        $("table").tablesorter(); 
   }); 

</script>

Where #container is the div where the table will be and table is the name of the table. I get the table loaded but sorting function is not working.

It works if I put the table directly in html in the page.. but I don't see the point in having a static table for sorting.

Any help would be very appreciated.

解决方案

$.load() performs a asynchronous request, i.e. the function does not wait for the data to arrive before returning. Therefore $("table").tablesorter(); is executed most likely before the table is added to the document. Either make it a synchronous call or (even better) pass a handler for the complete event to load.

http://api.jquery.com/load/:

.load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] )
url A string containing the URL to which the request is sent.
data A map or string that is sent to the server with the request.
complete(responseText, textStatus, XMLHttpRequest) A callback function that is executed when the request completes.

<script type="text/javascript">
  $(document).ready(function() { 
    $("#container").load(
      "table.php?randval="+Math.random(),
      null,
      function (responseText, textStatus, req) {
        $("table").tablesorter();
      }
    );
  }); 
</script>

这篇关于mysql的PHP生成的表:不与tablesorter的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆