【问题标题】:how to call url link from onchange in select dropdown如何从选择下拉列表中的onchange调用url链接
【发布时间】:2015-11-27 11:30:01
【问题描述】:

通常我从 GET 按钮调用 url '/filterSelectedStatus/'

<input type = "submit" value = "  Get  " align="center" onclick="javascript: form.action='/filterSelectedStatus/';"/>

但是我需要从 django 模板中的 onchange 调用相同的东西。但是下面的代码不起作用...

<select name = "selStatus" onchange = '/filterSelectedStatus/' method = 'get' >
    {% for list in statusList %}
        <option value = "{{ list}}"> {{ list }} </option>
    {% endfor %}
    <option selected= "{{ selStatus }}">{{ selStatus }} </option>
</select>

谢谢, 拉梅什。

【问题讨论】:

    标签: python html django django-templates


    【解决方案1】:

    onchange 属性用于调用 javascript,如文档 here 所述。在您的 javascript 中,创建如下函数:

    var filterSelectedStatus = function (e) {
        // Log the event e to the console to see what you can do with it
        console.log(e);
        // Do whatever you want here, like JavaScript GET requests
    };
    

    然后只需将您的 html 更改为

    <select name = "selStatus" onchange = 'filterSelectedStatus()'>
        {% for list in statusList %}
            <option value = "{{ list}}"> {{ list }} </option>
        {% endfor %}
        <option selected= "{{ selStatus }}">{{ selStatus }} </option>
    </select>
    

    【讨论】:

      猜你喜欢
      • 2011-08-15
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 2019-06-25
      • 2020-07-27
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      相关资源
      最近更新 更多