# 批量删除 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>

posted on 2019-04-24 20:43  满仟  阅读(113)  评论(0编辑  收藏  举报