如何排序表升序和降序时,单击链接
How to sort table ascending and descending when click on link
我有一个要求排序表时,单击标题链接。当点击链接时,首先时间表应该按升序排序时,单击下一个时间表应按降序排序。我写了PHP后端代码,它工作得很好。但我不知道如何传递所需的参数时,点击使用Javascript的链接。
My table html
<table class="table table-bordered table-striped">
<thead>
<tr>
<th><b>#</b></th>
<th><b id = "name_sort">Email</b> </th>
<th ><b >Name</b></th>
<th><b>Team</b> </th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Javascript $(function() {
$('#name_sort').click(function() {
window.location.href = "http://testdomain.com/admin-home?sort=email&sort_type=asc";
// when click again i need change the url to descending
http://testdomain.com/admin-home?sort=email&sort_type=desc
});
});
我不知道如何在前端使用JS实现它。请帮我解决这个问题。
你可以试试这个
PHP:首先获取next sorting type
默认为asc
$new_sort_type="asc"
if(isset($_REQUEST['sort_type']))
{
$sort_type = $_REQUEST['sort_type'];
if($sort_type=='asc')
{
$new_sort_type = 'desc';
}
}
jquery:现在将new sorting type
添加到jquery
中的url
中,如下所示
$(function() {
$('#name_sort').click(function() {
window.location.href = "http://testdomain.com/admin-home?sort=email&sort_type=<?php echo $new_sort_type;?>";
^ here add that variable
});
});
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 如何使用jQuery自动打开页面上的所有链接
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- jquery动画可以通过编程链接吗
- 在单击href链接的同时下载文件
- 尽管链接成功并已成功下载,但未找到NPM模块
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 单击页面上的链接后高度发生变化
- 将纯文本URL转换为可单击链接
- python-selenium-点击上升链接
- 一点javascript元编程&可链接的设置器
- ng视图外的链接重定向到ng视图内的页面
- 如何调用“;链接_;在onclick事件上使用Javascript
- 链接所有<a>Meteor
- 如何在Angular中的表的所有单元格中添加链接
- 通过链接重定向不;我不在jstree中工作
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 单击超链接时,如何使用Google Maps API v3缩放地图
- 如何排序表升序和降序时,单击链接