【发布时间】:2019-09-14 11:35:04
【问题描述】:
我根据表中的行数(在 tbody 内)在表中引入复选框。现在我想将复选框索引发送到烧瓶应用程序路由,以便复选框索引值存储在我的数据库中。我能够提醒复选框索引值 (0,1,4....) 但如何将此数组发送到烧瓶
我试过了
$('#match').on("click", function() {
var trs = $("input:checked").closest("tr"); //get tr elements of checked inputs
var indexes = $.map(trs, function(tr) { return $(tr).index(); }); //make an array containing the indexes of these tr elements
alert(indexes);
});
为表格创建一个复选框
$("#my_fo_id>tbody>tr").prepend("<input type='checkbox' id='check_fo' class='checkBoxClass_fo' style='margin-top: 5px;' name='fo_box'/>");
按钮
<button id="match" class="button button1" type="submit">Match</button>
表格代码
<table class="responsive display fo_data sortable" width="100%" id = "my_fo_id">
<tbody>
{% for row in row_data %}
<tr >
{% for col, row_ in zip(column_names, row) %}
<td >
{{ row_ }}
</td>
{% else %}
<td >
{{row_}}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
复选框值数组和警报数组
$('#match').on("click", function() {
var trs = $("input:checked").closest("tr"); //get tr elements of checked inputs
var indexes = $.map(trs, function(tr) { return $(tr).index(); }); //make an array containing the indexes of these tr elements
alert(indexes);
});
我想将数组发送到烧瓶应用程序路由(/Match),以便将数组存储在数据库中
@app.route('/Match', methods=['GET','POST'])
def manual():
if request.method == 'POST':
conn = sqlite3.connect('/C:/Users/patipra/Desktop/rdot_pac/database/test4.db')
cr = conn.cursor()
cr.execute("DROP TABLE IF EXISTS match_id")
cr.execute("CREATE TABLE match_id (ID INTEGER)")
return render_template('frame_set.html')
else:
return render_template('home.html')
【问题讨论】:
标签: javascript python html flask