美文网首页
select下拉option跳转页面

select下拉option跳转页面

作者: 王文强Python | 来源:发表于2023-11-29 13:55 被阅读0次

第一种方式:

<script>
        $(document).ready(function () {
            $('#jys').change(function () {
                var value = $('#jys option:selected').val();
                var URL = "{% url 'detail' %}?symbol=" + value;
                window.location.href = URL
            })
        });
</script>

<select id="jys" style="margin-right: 5%">
       <option class="sy" value="sh">上海交易所</option>
       <option class="sy" value="dl">大连交易所</option>
       <option class="sy" value="zz">郑州交易所</option>
</select>

第二种方式

 <select onchange="window.location=this.value;" style="margin-right: 5%">
       {% for sy,name in symbols_sh.items %}
               <option value="{% url 'detail' %}?symbol={{ sy }}">{{ name }}</option>
        {% endfor %}
</select>

相关文章