我有这组单选按钮:
{% 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" onchange="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" onchange="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" onchange="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>
{% end %}
我有一个 js 函数可以更改单选按钮的检查,当单选按钮检查更改时,我会提交表单工作。如果我单击单选按钮,一切正常。但是如果我使用改变检查的js函数,这不起作用。为什么?
谢谢你。
编辑
这是我的 js 函数:
<script>
function checkall(perm){
var permall = parseInt(perm);
switch (permall){
case 0:
{% for user in users %}
document.getElementById("perms_{{user.id}}_0").checked=true
{% end %}
break;
case 1:
{% for user in users %}
document.getElementById("perms_{{user.id}}_1").checked=true
{% end %}
break;
case 4:
{% for user in users %}
document.getElementById("perms_{{user.id}}_4").checked=true
{% end %}
break;
}
}
</script>