flask-如何在同一HTML页面中显示选定的下拉值? [英] flask - How to display a selected dropdown value in same html page?

查看:54
本文介绍了flask-如何在同一HTML页面中显示选定的下拉值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个flask应用程序,其中有一个下拉列表,当我选择一个选项时,它应显示在下拉列表"Your selected score:"和选定分数下方.

I am developing a flask application, in which I have a dropdown, when I select an option, it should display below the dropdown "Your selected score : " and the selected score.

我正在显示如下所示的下拉列表:

I am displaying a dropdown like below :

<select name="score">
    {% for score in range(6) %}
    <option value={{score}}> {{score}} </option>
    {% endfor %}
</select>

我正在显示thr的选定值:

I am displying thr selected value like :

您选择的分数:{{分数}}

我尝试了很多,却找不到任何东西.任何线索都将有所帮助.

I tried and search a lot couldn't find anything. Any leads would be helpful.

推荐答案

您需要更改事件.

尝试

<select name="score" onchange="updateSelected(event)">
    {% for score in range(6) %}
    <option value={{score}}> {{score}} </option>
    {% endfor %}
</select>
<div id="res"></>

<script>
    function updateSelected(event) {
        document.getElementById('res').innerHTML = 'Your selected score : ' + event.target.value;
    }
</script>

这篇关于flask-如何在同一HTML页面中显示选定的下拉值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆