标签:标题 route attr sub put checked get render order
# 批量删除 py
@index_blue.route(‘/deleteall‘,methods=[‘GET‘,‘POST‘])
def delete_all():
if request.method == ‘POST‘:
all_id = request.form.getlist(‘news‘)
for id in all_id:
n = News.query.get(id)
db.session.delete(n)
db.session.commit()
news_list = News.query.all()
d = {}
d[‘news_list‘] = news_list
return render_template(‘/delete_all.html‘,data=d)
# html
<form method="post">
<table border="1">
<tr>
<td><input type="checkbox" id="all">全选</td>
<td>标题</td>
</tr>
{% for i in data.news_list %}
<tr>
<td><input type="checkbox" name="news" value="{{ i.id }}" id=""></td>
<td>{{ i.title }}</td>
</tr>
{% endfor %}
</table>
<button type="submit">删除</button>
</form>
# 导入jquery
<script src="../static/js/jquery-1.12.4.min.js"></script>
# 全选jquery
<script>
$(‘#all‘).click(function () {
if(this.checked)
{
$("input[name=‘news‘]").attr(‘checked‘,true);
}
else
{
$("input[name=‘news‘]").attr(‘checked‘,false);
}
})
</script>
标签:标题 route attr sub put checked get render order
原文地址:https://www.cnblogs.com/manqian/p/10764836.html