Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用表单名称在javascript中提交表单_Javascript_Html_Django_Forms - Fatal编程技术网

使用表单名称在javascript中提交表单

使用表单名称在javascript中提交表单,javascript,html,django,forms,Javascript,Html,Django,Forms,我正在使用django模板在网页中动态生成带有隐藏输入的表单,这些表单应该在单击相关文本标签时提交。问题是我就是不能让它工作 {% for tag in tags %} <form name="remove_{{ tag }}" id="{{ tag }}" action="/filter" method="post" accept-charset="utf-8"> <input type="hidden" name="remove_tag" value ="{{ ta

我正在使用django模板在网页中动态生成带有隐藏输入的表单,这些表单应该在单击相关文本标签时提交。问题是我就是不能让它工作

{% for tag in tags %}
<form name="remove_{{ tag }}" id="{{ tag }}" action="/filter" method="post" accept-charset="utf-8">
    <input type="hidden" name="remove_tag" value ="{{ tag }}" />
</form>

<a href="javascript: remove_tag({{ tag }})">{{ tag }}</a>
{% endfor %}

<script type="text/javascript">
    function remove_tag(tag) {  
        document.getElementById(tag).submit();
        return false;
    }
</script>
(将表单名称更改为tag),但收到几乎相同的错误,但使用“undefined”而不是null

在第二个示例中,javascript函数似乎试图将“tag”解释为整数。如果我使用一个整数,它可以正常工作。我可以首先使用forloop.counter来生成表单,但这有点难看,并且使代码更难维护

表单上是否有其他调用submit()的功能性方法?

引号:

<a href="javascript: remove_tag('{{ tag }}')">{{ tag }}</a>

必须正确引用“tag”值才能使Javascript代码片段语法正确

<a href="javascript: remove_tag('{{ tag }}')">{{ tag }}</a>