【发布时间】:2016-10-04 14:38:39
【问题描述】:
我正在尝试在 jquery ui 对话框中动态创建的表上使用 tablesorter,但 tablesorter 似乎不起作用。这意味着结果是一个简单的 html 表格,没有像 tablesorter 的“斑马”那样排序或布局。 我的代码:
var content = '<table id="searchtable" class="tablesorter"><thead><tr><th>Date</th><th>Subject</th></th></tr>';
content += '</thead><tbody><tr><td>04.10.2016 09:00</td><td>some Text</td></tr>';
content += '<tr><td>04.10.2016 12:00</td><td>another Text</td></tr></tbody></table>';
$("#searchButton").button().click(function() {
$('#searchdialog').html(content).dialog({
width: "auto",
open: function() {
$('#searchtable').tablesorter();
}
});
});
.tablesorter {
width: auto;
cursor: pointer;
widgets: ['zebra'];
}
<link href="https://mottie.github.com/tablesorter/css/theme.blue.css" rel="stylesheet"/>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="http://mottie.github.com/tablesorter/js/jquery.tablesorter.js"></script>
<div id='searchButton'>Search</div>
<div id="searchdialog" title="Search Dialog"></div>
这是我在 stackoverflow 上的第一个问题,我对插入代码等不太熟悉,我从我的 jsfiddle (https://jsfiddle.net/JMKivi/kumrgyaw/12/) 复制/粘贴了代码。因此,请让我知道使用 stackoverflow 是否有错误或似乎缺少重要的东西。
编辑:我现在将<button id='searchButton'>Search</button> 更改为<div id='searchButton'>Search</div>。它在这里仍然有效,但在 jsfiddle 和我的生产环境中无效。无论如何感谢您的帮助。
【问题讨论】:
标签: jquery jquery-ui jquery-ui-dialog tablesorter