我可以从模型中获取数据并以表格格式显示。但是现在我想对少数属性使用JavaScript,以便如何遍历JavaScript(如果单击了复选框,则禁用输入字段)。以下是我尝试使用Jinja在JavaScript中进行循环的代码,但无法正常工作。
<<models>>
class datavalue(models.Model):
myname=models.CharField(max_length=250,default=None)
finalnames=models.CharField(max_length=250,default=None)
def __str__(self):
return self.myname
<<views.py>>
def context(request):
myvalue = datavalue.objects.all()
return render(request, 'context.html', {'dbvalue':myvalue})
<<context.html>>
{% for i in dbvalue %}
<tr>
<td > {{ i.myname }}</td>
<td>C1</td>
<td>L1</td>
<td>
<label class="radiocontainer" >Manual
<input type="radio" name={{ i.myname }} checked><span class="circle"></span>
</label><br><br>
<label class="radiocontainer">Automatic
<input type="radio" name={{ i.myname }} id={{i.id}} onclick="disablefun()"><span class="circle"></span>
</label>
</td>
<td><input type="text" id={{i.finalnames}}></td>
</tr>
<script>
function disablefun() {
if (document.getElementById({{i.id}}).checked == true){
document.getElementById({{i.finalnames}}).disabled=true;
} else {
text.style.display = "none";
}
}
</script>
{% endfor %}
</table>