我非常密切地关注http://ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/,效果很好,但似乎我必须已经在 HTML 中有一个表格。我想稍后在程序中构建一个表,然后通过 treeTable 运行它以获得可扩展视图。当我摆脱“$(document).ready(function()”并将其替换为常规函数,然后在构建表后调用该函数时,视图无法正常工作。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery/jquery.js"> </script>
<link href="./jquery/jquery.treeTable.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./jquery/jquery.treeTable.js"></script>
<script type="text/javascript">
function init() {
createTable();
$("#pathTable").treeTable();
}
</script>
<script type="text/javascript">
function createTable() {
document.write('<table id="pathTable"><tbody>');
document.write('<tr id="node-0"><td>node0</td></tr>');
document.write('<tr id="node-1" class="child-of-node-0">');
document.write('<td>node1</td></tr>');
document.write('<tr id="node-2" class="child-of-node-1">');
document.write('<td>node2</td></tr>');
document.write('</tbody></table>');
}
</script>
</head>
<body onload="init()">
</body>
</html>