【发布时间】:2020-12-22 19:48:18
【问题描述】:
我的站点中有一张桌子,上面有玩家姓名和服务器。但我需要它们是可点击的,并且需要具有过滤效果。
我的意思是,如果你点击玩家姓名 => 排行榜将像往常一样再次加载并显示服务器玩家玩..
和服务器名称 => 排行榜将像往常一样再次加载并显示在服务器上玩的玩家
另一个示例: 现在假设我点击“用户名”肯”。点击后,排行榜只显示用户名“ken”和播放“ken”的服务器。
注意:表中的数据是从外部 JSON 文件中获取的, https://dayz-n-chill.herokuapp.com/getglobal
排行榜图片:image
我的脚本:
function responseHandler(res) {
res.forEach(function (row, i) {
row.index = i + 1
})
return res
}
function ajaxRequest(params) {
var url = 'https://dayz-n-chill.herokuapp.com/getglobal'
jQuery.get(url, jQuery.param(params.data)).then(function (res) {
params.success(res);
console.log(res);
// this is what i tried so far
var x = $("td").text();
$("td").click(function () {
var rows = $("#tableBody").find("tr").hide();
rows.filter(":contains('$(this).text()')").show();
})
})
}
//
我的 HTML 代码:
<table class="table table-bordered table-hover" data-toggle="table" data-search="true" data-ajax="ajaxRequest"
data-pagination="true" data-height="700" data-response-handler="responseHandler" data-toolbar="#toolbar">
<thead class="thead-dark">
<tr>
<th scope="col" data-field="index" data-sortable="true">Rank</th>
<th scope="col" data-field="userName" data-sortable="true" id="user_name">Username</th>
<th scope="col" data-field="serverName" data-sortable="true">Server Name</th>
<th scope="col" data-field="Kills" data-sortable="true">Kills</th>
<th scope="col" data-field="Deaths" data-sortable="true">Deaths</th>
<th scope="col" data-field="headshot" data-sortable="true">Headshots</th>
<th scope="col" data-field="killStreak" data-sortable="true">Kill Streak</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
【问题讨论】:
标签: javascript html jquery json ajax