如何在选择下拉列表中从onchange调用url链接

时间:2015-09-02 05:05:11

标签: python html django django-templates

通常情况下,我使用网址'/ filterSelectedStatus /'

从GET按钮调用
<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>

谢谢, 拉梅什。

1 个答案:

答案 0 :(得分:0)

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>