我正在动态生成一个表格以及列标题。
如何使列可点击(NO JavaScript!),以便在单击它们时,它们会向查询添加 sort=columnNameHere
条目,并且使用该查询重新加载当前页面?
最佳答案
了解您的服务器端语言会很有帮助,但由于您没有包含该语言,因此您需要代码输出 html,如下所示...
<table>
<thead>
<th><a href="test.html?sort=Name">Name</a></th>
<th><a href="test.html?sort=Location">Location</a></th>
</thead>
<tr>
<td>Bob</td>
<td>Canada</td>
</tr>
</table>
在服务器上,您需要确保从获取变量集合中获取排序变量并将其应用于源查询。在伪代码中,这将类似于:
currentSort = Request["sort"]
data = db.Execute("select * from customersorder by " + sqlescape(currentSort))
//write table header
foreach col in columns
write("<th><a href='test.html?sort=" + col + "'>" + col + "</a>")
//close header, start data
for each row in data
write...
关于python - HTML 表格——在标题中放置链接进行排序? (无 JavaScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6297149/