Jam*_*mes 3 html javascript django django-templates
背景:我有一个动态表(因为我直到运行时才知道它的大小/元素),我试图在其中使用 javascript 函数填充文本区域。为此,我计划将文本区域的 id 以及我想将其填充到 javascript 函数中的值一起传递。
问题是我在为每个文本输入字段创建动态 id 值时遇到问题。这就是我目前尝试这样做的方式:
{% with "input_"|add:applicant.id as idName %}
<input id="{{ idName }}" type="text" value="">
<input type="button" hidden="TRUE" onclick="">
{{ idName }}
<script>
putTags({{ idName }}, {{ tags }});
</script>
{% endwith %}
Run Code Online (Sandbox Code Playgroud)
函数 putTags() 将填充文本输入的内容。不幸的是,这不起作用,因为它将每个人的 id 分配给“input_”,而没有附加申请人.id 的值(我已经检查过,每次迭代的申请人.id 都有一个正确的 id)。难道我做错了什么?有没有更简单的方法来创建这些唯一 ID?
你可以试试这样的
<input id="input_{{ applicant.id }}" type="text" value="">
<input type="button" onclick="putTags('input_{{ applicant.id }}', {{ tags }});">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4624 次 |
| 最近记录: |