- 如何在html页面显示下拉框
<form method = 'POST', action="/addStudent/">
<p>学生名称:<input type = 'text' name = "Student_Name"></input></p>
<p>班级:
<select name = 'class_id'>
{% for items in results %}
<option value = '{{ items.0 }}'> {{ items.1 }}</option>
{% endfor %}
</select>
</p>
<input type = 'submit' value = "提交"></input>
</form>
页面效果:
- 总结
下拉框的实现,使用select 标签和option标签
下拉框的选择值提交,在select标签使用name,在option标签使用value。
这样传送到后端时,就可以用获得其选择内容
class_id = request.POST.get('class_id')
Student_Name = request.POST.get('Student_Name')