我在使用 tablesorter 对在 hta 中生成的表进行排序时遇到了一些问题。我不知道如何在新表上启用 tablesorter。Bellow 是一个测试 html 文件。出于测试目的,我建议使用 IE,因为它包含 VBS。谢谢!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>Test Tablesorter</title>
<script type="text/javascript" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" src="js/chili-1.8b.js"></script>
<script type="text/javascript" src="js/docs.js"></script>
<script type="text/javascript">
$(function() {
$("table")
.tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")});
});
</script>
</head>
<style>
table.tablesorter
{
background-color: #CDCDCD;
font-family: arial;
font-size: 8pt;
margin: 10px 0pt 15px;
text-align: left;
width: 100%;
}
table.tablesorter thead tr th, table.tablesorter tfoot tr th
{
background-color: #e6EEEE;
border: 1px solid #FFF;
font-size: 8pt;
padding: 4px;
}
table.tablesorter thead tr .header
{
background-image: url(img/bg.gif);
background-position: center right;
background-repeat: no-repeat;
cursor: pointer;
}
table.tablesorter tbody td
{
background-color: #FFF;
color: #3D3D3D;
padding: 4px;
vertical-align: top;
}
table.tablesorter tbody tr.odd td
{
background-color: #F0F0F6;
}
table.tablesorter thead tr .headerSortUp
{
background-image: url(img/asc.gif);
}
table.tablesorter thead tr .headerSortDown
{
background-image: url(img/desc.gif);
}
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp
{
background-color: #8dbdd8;
}
</style>
<body>
<script language="VBscript">
Sub CheckSystem
strHTML = strHTML & "<table cellspacing='1' class='tablesorter' id='table'>"
strHTML = strHTML & "<thead> "
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<th>Name</th>"
strHTML = strHTML & "<th>Major</th>"
strHTML = strHTML & "<th>Sex</th>"
strHTML = strHTML & "<th>English</th>"
strHTML = strHTML & "<th>Japanese</th>"
strHTML = strHTML & "</tr>"
strHTML = strHTML & "</thead> "
strHTML = strHTML & "<tfoot> "
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<th>Name</th>"
strHTML = strHTML & "<th>Major</th>"
strHTML = strHTML & "<th>Sex</th>"
strHTML = strHTML & "<th>English</th>"
strHTML = strHTML & "<th>Japanese</th>"
strHTML = strHTML & "</tr>"
strHTML = strHTML & "</tfoot> "
strHTML = strHTML & "<tbody>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td>Student01</td>"
strHTML = strHTML & "<td>Languages</td>"
strHTML = strHTML & "<td>male</td>"
strHTML = strHTML & "<td>80</td>"
strHTML = strHTML & "<td>75</td>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td>Student02</td>"
strHTML = strHTML & "<td>Languages</td>"
strHTML = strHTML & "<td>male</td>"
strHTML = strHTML & "<td>80</td>"
strHTML = strHTML & "<td>60</td>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td>Student03</td>"
strHTML = strHTML & "<td>Languages</td>"
strHTML = strHTML & "<td>male</td>"
strHTML = strHTML & "<td>60</td>"
strHTML = strHTML & "<td>40</td>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td>Student04</td>"
strHTML = strHTML & "<td>Languages</td>"
strHTML = strHTML & "<td>male</td>"
strHTML = strHTML & "<td>30</td>"
strHTML = strHTML & "<td>20</td>"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "</tbody>"
strHTML = strHTML & "</table>"
strHTML = strHTML & "<span id='pager' class='pager'>"
strHTML = strHTML & "<form>"
strHTML = strHTML & "<img src='img/first.png' class='first'/>"
strHTML = strHTML & "<img src='img/prev.png' class='prev'/>"
strHTML = strHTML & "<input type='text' class='pagedisplay'/>"
strHTML = strHTML & "<img src='img/next.png' class='next'/>"
strHTML = strHTML & "<img src='img/last.png' class='last'/>"
strHTML = strHTML & "<select class='pagesize'>"
strHTML = strHTML & "<option selected='selected' value='5'>5</option>"
strHTML = strHTML & "<option value='10'>10</option>"
strHTML = strHTML & "<option value='30'>30</option>"
strHTML = strHTML & "<option value='40'>40</option>"
strHTML = strHTML & "</select>"
strHTML = strHTML & "</form>"
strHTML = strHTML & "</span>"
DataArea.InnerHTML = strHTML
End Sub
</script>
<body>
<p><span id="DataArea"></span></p>
<input type="button" class="button" value="CheckSystem" style="width:70" onClick="VBScript:CheckSystem">
</body>
</html>
在 dartacus 的帮助下,我找到了一个不涉及超时的临时解决方案(分页仍然无法正常工作)
<script type="text/javascript">
$(document).ready(function(){
$('#test-tablesorter').click(function(){
$('table').addClass('tablesorter').tablesorter();
$('table')
.tablesorterPager({container: $("#pager")});
});
});
</script>
我在按钮上添加了 id="table-sorter"。网上有关于这个脚本的分页插件的一些问题。我需要进一步调查。
我发现了分页的问题。这是由每个原始文件末尾缺少的“/”引起的。我的原始帖子没有正确关闭原始帖子(可能在我复制/粘贴代码以创建更多数据时发生)。表语法是问题:"<"/tr">"