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

我找到了这个很棒的jQuery表列表插件,但是我不能让它在PHP生成的表中工作。这是代码:

<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.

其中#container是表所在的div,而table是表的名称。我加载了表,但是排序函数不起作用。

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.

如果我把表直接放在页面的html格式里就可以了。但是我不认为使用静态表进行排序有什么意义。

Any help would be very appreciated.

如有任何帮助,我们将不胜感激。

1 个解决方案

#1


3

$.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.

$.load()执行异步请求,即函数不等待数据到达才返回。因此美元(“表”).tablesorter();在将表添加到文档之前执行。要么使它成为一个同步调用,要么(甚至更好)为要加载的完整事件传递一个处理程序。

http://api.jquery.com/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>

更多相关文章

  1. PHP空间函数类似于ASP空间()
  2. PHP中类和对象的相关函数
  3. 来自加载页面的Javascript响应未显示在中,尽管我可以在firebug中
  4. php函数 什么时候使用fflush函数
  5. 如何加载json文件?
  6. 如何调试UPDATE函数在PHP中无法正常工作的原因?
  7. PHP结束后执行函数
  8. 在simplexml_load_file中加载url时出错
  9. 迭代文件夹中的CSV文件,并使用PHP将数据加载到MySQL中

随机推荐

  1. android tabhost
  2. Android Input Event Dispatching
  3. Android 登录界面xml代码
  4. Android关于流媒体播放(1)
  5. VLC on Android
  6. android 程序调试入门
  7. android TabLayout Indicator 圆角
  8. android PopupWindow
  9. UI设计师的 Android 备忘录
  10. (转)Working With Android Contacts