Mysql PHP生成的表:不能使用表
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>
更多相关文章
- PHP空间函数类似于ASP空间()
- PHP中类和对象的相关函数
- 来自加载页面的Javascript响应未显示在中,尽管我可以在firebug中
- php函数 什么时候使用fflush函数
- 如何加载json文件?
- 如何调试UPDATE函数在PHP中无法正常工作的原因?
- PHP结束后执行函数
- 在simplexml_load_file中加载url时出错
- 迭代文件夹中的CSV文件,并使用PHP将数据加载到MySQL中