我有这个js函数:
function createFormAndSubmit(val){
{% for user in users %}
var submitForm = document.createElement("form_user_{{ user.id }}");
document.body.appendChild(submitForm);
submitForm.method = "POST";
var newid = document.createElement("input");
newid.type = "hidden";
newid.value = "{{ user.id }}";
submitForm.appendChild(newid);
var newperm = document.createElement("input");
newperm.type = "radio";
newperm.value = val;
submitForm.appendChild(newperm);
submitForm.action= "/networks/{{ net.id }}/sensors/{{ sens.id }}/rights";
document.forms['form_user_{{ user.id }}'].submit();
//submitForm.submit();
{% end %}
}
它被这个 html 元素调用:
{% if users %}
<tr>
<td>
<div>
<strong>All users</strong>
</div>
</td>
<td>
<label class="radio inline" onclick="createFormAndSubmit('0');">
<input type="radio" name="permsall" id="all_0" value="0">
None
</label>
<label class="radio inline" onclick="createFormAndSubmit('1');">
<input type="radio" name="permsall" id="all_1" value="1">
Read
</label>
<label class="radio inline" onclick="createFormAndSubmit('4');">
<input type="radio" name="permsall" id="all_4" value="4">
Read + Commands
</label>
</td>
</tr>
我想将 userid 和 perm(权限)传递给表单,但是如果我打印传递给 Web 服务器的值,我会看到 perm 始终为 0。为什么?js函数的错误在哪里?