我有这个代码:
{% for user in users %}
<form name="form_user_{{ user.id }}" method="post" action="/networks/{{ net.id }}/sensors/{{ sens.id }}/rights">
<tr>
<td>
<div>
{{ escape(user.name) }}
<input type='hidden' name="id" value='{{ user.id }}'>
</div>
</td>
<td>
<label class="radio inline" onclick="document.forms['form_user_{{ user.id }}'].submit();">
<input type="radio" name="perms" id="perms_{{user.id}}_0" value="0">
None
</label>
<label class="radio inline" onclick="document.forms['form_user_{{ user.id }}'].submit();">
<input type="radio" name="perms" id="perms_{{user.id}}_1" value="1">
Read
</label>
<label class="radio inline" onclick="document.forms['form_user_{{ user.id }}'].submit();">
<input type="radio" name="perms" id="perms_{{user.id}}_4" value="4">
Read + Commands
</label>
{{ xsrf_form_html() }}
</td>
</tr>
</form>
我会将这段代码放在 html 页面底部的函数脚本中,并将该函数与 onClick 事件相关联。
我正在尝试编写该函数,但它不起作用。
这个函数的错误在哪里?
function createFormAndSubmit(){
{% for user in users %}
var submitForm = document.createElement("form_user_{{ user.id }}");
document.body.appendChild(submitForm);
submitForm.method = "POST";
var newElement = document.createElement("<input type='hidden' name='id' value='{{ user.id }}'>");
inputForm.appendChild(newElement);
var newElement = document.createElement("<input type='radio' name='perms' id='perms_{{user.id}}_0' value='0'>");
inputForm.appendChild(newElement);
submitForm.action= "/networks/{{ net.id }}/sensors/{{ sens.id }}/rights";
document.forms['form_user_{{ user.id }}'].submit();
submitForm.submit();
{% end %}
}
我正在尝试构建附加树结构中每个元素的表单。