如何为django模板中的标记创建动态id
Background: I have a dynamic table (as in I don't know its size/elements until runtime) where I am trying to populate a text area with a javascript function. To do this I plan on passing the text area's id along with the values I want to populate it with into the javascript function.
背景:我有一个动态表(在运行时之前我不知道它的大小/元素),我试图用javascript函数填充一个文本区域。为此,我计划将文本区域的id连同要填充的值一起传递到javascript函数中。
The problem is I am having trouble creating a dynamic id value for each text input field. This is how i am currently attempting to do this:
问题是我在为每个文本输入字段创建动态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 %}
where the function putTags() will populate the text input's contents. Unfortunately this doesn't work, as it assigns everyone's id to "input_" without appending applicant.id's value (and I have checked, applicant.id has a correct id for each iteration). Am i doing something wrong? Is there an easier way to create these unique IDs?
函数putTags()将填充文本输入的内容。不幸的是,这不起作用,因为它将每个人的id分配给“input_”,而不附加申请人。id的值(我查过了,申请人。id对每个迭代都有一个正确的id)。我做错什么了吗?是否有更简单的方法来创建这些唯一的id ?
1 个解决方案
#1
2
You can try something like this
你可以试试这个
<input id="input_{{ applicant.id }}" type="text" value="">
<input type="button" onclick="putTags('input_{{ applicant.id }}', {{ tags }});">
更多相关文章
- 我无法理解为什么我的代码中的单击选择文本
- 用无序列表键入文本脚本
- jQuery动画div滑动,不覆盖文本。
- 如何让这段插入的innerHTML 里动态赋予的函数跑起来!
- Jquery在两个元素之间更改文本
- 使用下一个div中的文本设置“下一个”按钮的文本
- jQuery animate()函数没有动画
- HTML基础 img标签alt属性 当图片加载失败的时候显示为文本
- 【WEB基础】HTML & CSS 基础入门(3)段落及文本