问题描述
如何在另一个页面上重定向并从表中传递url中的参数?
我在tornato模板中创建了这样的东西
How to redirect on another page and pass parameter in url from table ?I've created in tornato template something like this
<table data-role="table" id="my-table" data-mode="reflow">
<thead>
<tr>
<th>Username</th>
<th>Nation</th>
<th>Rank</th>
<th></th>
</tr>
</thead>
<tbody>
{% for result in players %}
<tr>
<td>{{result['username']}}</td>
<td>{{result['nation']}}</td>
<td>{{result['rank']}}</td>
<td><input type="button" name="theButton" value="Detail"
></td>
</tr>
</tbody>
{% end %}
</table>
我希望当我按 / player_detail重定向细节时? username = username
并显示该播放器的所有详细信息。
我试过 href =javascript:window.location.replace('./ player_info');
在输入标签内但不知道如何放结果['用户名'] in。
怎么做?
and I would like when I press detail to be redirect on /player_detail?username=username
and show all detail about that player.I tried with href="javascript:window.location.replace('./player_info');"
inside input tag but don't know how to put result['username'] in. How to do this ?
推荐答案
将用户名设置为 data-username
该按钮的属性以及一个类:
Set the user name as data-username
attribute to the button and also a class:
HTML
<input type="button" name="theButton" value="Detail" class="btn" data-username="{{result['username']}}" />
JS
$(document).on('click', '.btn', function() {
var name = $(this).data('username');
if (name != undefined && name != null) {
window.location = '/player_detail?username=' + name;
}
});
编辑:
此外,您只需检查 undefined
&& null
使用:
Also, you can simply check for undefined
&& null
using:
$(document).on('click', '.btn', function() {
var name = $(this).data('username');
if (name) {
window.location = '/player_detail?username=' + name;
}
});
正如本中提到的那样
if (name) {
}
将评估为真如果价值不是:
will evaluate to true if value is not:
- null
- undefined
- NaN
- 空字符串()
- 0
- false
- null
- undefined
- NaN
- empty string ("")
- 0
- false
上面的列表代表ECMA / Javascript中所有可能的假值。
The above list represents all possible falsy values in ECMA/Javascript.
这篇关于如何重定向另一个页面并从表中传递url中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!