python - 根据 onclick 表值预选下拉选项并导航到另一个页面
问题描述
我想根据 onclick 表值预先选择下拉选项,同时导航到下拉选项的另一页。
下面是代码
应用程序.py
@app.route('/userinfo',methods=["POST","GET"])
def userinfo():
result = cursor.execute("SELECT * FROM user ORDER BY id")
user= cursor.fetchall()
result1 = cursor.execute("SELECT * FROM header ORDER BY id ")
header = cursor.fetchall()
return render_template('userinfo.html', user= user, result1=result1)
用户信息.html
<div class="form-group">
<div class="cols-sm-10">
<h5>user onfo </h5>
<select name="name1" class="teamForm" id="teamDropdown" type="text" placeholder="Select projects">
{% for i in user %}
<option id="{{ i.id }}" value= "{{ i.id }}">{{ i.name }}</option>
{% endfor %}
</select>
<select name="tasks" class="teamForm2" id="teamDropdown1" type="text" method="POST">
{% for j in header %}
<option id="{{ j.id }}" value= "{{ j.header1 }}" selected>{{j.header1 }}</option>
<option id="{{ j.id }}" value= "{{ j.header2 }}">{{j.header2 }}</option>
<option id="{{ j.id }}" value= "{{ j.header3 }}" selected>{{j.header3 }}</option>
<option id="{{ j.id }}" value= "{{ j.header4 }}" selected>{{j.header4 }}</option>
{% endfor %}
</select>
</div>
</div>
索引.html
<thead>
{% for row in header %}
<tr>
<th data-pk="{{row.id}}">{{row.id}}</th>
<th data-pk={{row.id}}">{{row.name}}</th>
<th data-pk="{{row.id}}">{{row.date}}</th>
<th data-pk="{{row.id}}">{{row.header1}}</th>
<th data-pk="{{row.id}}">{{row.header2}}</th>
<th data-pk="{{row.id}}">{{row.header3}}</th>
</tr>
{% endfor %}
</thead>
<tbody>
{% for row in emp %}
<tr>
<td data-pk="{{row.id}}">{{row.id}}</td>
<td data-name="name" class="name" data-type="text" data-pk="{{row.id}}">{{row.name}}</td>
<td class="under-limit" onclick="location.href='/userinfo'">{{row.task1}}</td>
<td class="under-limit" onclick="location.href='/userinfo'">{{row.task2}}</td>
<td class="under-limit" onclick="location.href='/userinfo'">{{row.task3}}</td>
</tr>
{% endfor %}
{/tbody>
当我单击表格单元格时,根据所选的行和列,必须选择下拉选项,同时导航到另一个页面。我试着用 Jquery 做,但我做不到。请任何人都可以帮助我。
解决方案
我找到了解决方案。
$('.under-limit').on('click', function(id) {
let $cell = $(this);
let txt = $cell.text();
var cellIndex = $cell.index()-1;
var header = $cell.closest('table').find('th').eq($cell.index()-2).text();
alert(txt + ':' + header);
使用导航到另一个页面的 window.location.href 传递标题值。
从上面的代码中删除 onclick 事件
推荐阅读
- java - 在动态更新的表中捕获更改
- teiid - teiid 中的 DayOfWeek 函数在下推到 Oracle 时取决于语言环境
- jenkins - 无法卸载詹金斯
- typescript - 如何正确地将函数转换为可更新的
- regex - 将 Chef insert_line_if_no_match 与“\:”一起使用
- matlab - 如何创建包含结构组件内容的元胞数组?MATLAB
- python - 从python pandas中的单词中删除空格
- python - 如何在另一个包含 kivy 代码的文件中打开包含 kivy 代码的 python 文件
- google-cloud-platform - 开始日期和结束日期字段以匹配数据工作室开始和结束期间
- c++ - 代码在我的电脑上运行良好,但我在提交到 coursera 时遇到了未知信号 11 问题