Javascript 如何在“中”的项中传递此列表索引0;地点;功能
如何在javascript函数中传递此列表项Javascript 如何在“中”的项中传递此列表索引0;地点;功能,javascript,python,html,jinja2,Javascript,Python,Html,Jinja2,如何在javascript函数中传递此列表项 {% for a in ard %} <h3 style="font-style:italic; font-family:verdana;">{{a[0]}}</h3><br> <li>{{a[1]}}</li> <li>{{a[2]}}</li> <li&g
{% for a in ard %}
<h3 style="font-style:italic; font-family:verdana;">{{a[0]}}</h3><br>
<li>{{a[1]}}</li>
<li>{{a[2]}}</li>
<li>{{a[3]}}</li>
<button onclick="Place({{a[0]}});">Place order</button>
<hr>
{% endfor %}
{%in-ard%}
{{a[0]}}
{{a[1]}
{{a[2]}
{{a[3]}
下单
{%endfor%}
将它们包装在一个节点中,然后使用querySelectorAll
{% for a in ard %}
<h3 style="font-style:italic; font-family:verdana;">{{a[0]}}</h3><br>
<ul class="item-list">
<li>{{a[1]}}</li>
<li>{{a[2]}}</li>
<li>{{a[3]}}</li>
</ul>
<button onclick="Place({{a[0]}});">Place order</button>
<hr>
{% endfor %}
{%in-ard%}
{{a[0]}}
- {{a[1]}
- {{a[2]}
- {{a[3]}
下单
{%endfor%}
document.querySelectorAll('.item list>li')
将它们包装在一个节点中并使用querySelectorAll
{% for a in ard %}
<h3 style="font-style:italic; font-family:verdana;">{{a[0]}}</h3><br>
<ul class="item-list">
<li>{{a[1]}}</li>
<li>{{a[2]}}</li>
<li>{{a[3]}}</li>
</ul>
<button onclick="Place({{a[0]}});">Place order</button>
<hr>
{% endfor %}
{%in-ard%}
{{a[0]}}
- {{a[1]}
- {{a[2]}
- {{a[3]}
下单
{%endfor%}
document.querySelectorAll('.item list>li')
假设ard
是一个字符串元组,如from注释(“Uno R3”,“带USB”,“microroll”)
中提供的。为了从数据结构中创建列表,您应该使用for In循环创建每个列表项标记
您在jinja2上的代码类似于以下代码:
{# Title using the first element of the tuple #}
<h3 style="font-style:italic; font-family: verdana;">
{{ ard[0] }}
</h3>
<br />
<ul id="arduino-items">
{% for item in ard %}
<li>{{ item }}</li>
{% endfor %}
</ul>
<button onclick="Place( {{ a[0] }} );">Place order</button>
<hr>
{#Title使用元组的第一个元素#}
{{ard[0]}
{%用于ard%中的项目}
- {{item}}
{%endfor%}
下单
呈现的结果HTML如下所示:
{# Title using the first element of the tuple #}
<h3 style="font-style:italic; font-family: verdana;">
{{ ard[0] }}
</h3>
<br />
<ul id="arduino-items">
{% for item in ard %}
<li>{{ item }}</li>
{% endfor %}
</ul>
<button onclick="Place( {{ a[0] }} );">Place order</button>
<hr>
Uno R3
- Uno R3
- 使用USB
- 微辊
下单
假设ard
是一个字符串元组,如from注释(“Uno R3”、“带USB”、“microroll”)
。为了从数据结构中创建列表,您应该使用for In循环创建每个列表项标记
您在jinja2上的代码类似于以下代码:
{# Title using the first element of the tuple #}
<h3 style="font-style:italic; font-family: verdana;">
{{ ard[0] }}
</h3>
<br />
<ul id="arduino-items">
{% for item in ard %}
<li>{{ item }}</li>
{% endfor %}
</ul>
<button onclick="Place( {{ a[0] }} );">Place order</button>
<hr>
{#Title使用元组的第一个元素#}
{{ard[0]}
{%用于ard%中的项目}
- {{item}}
{%endfor%}
下单
呈现的结果HTML如下所示:
{# Title using the first element of the tuple #}
<h3 style="font-style:italic; font-family: verdana;">
{{ ard[0] }}
</h3>
<br />
<ul id="arduino-items">
{% for item in ard %}
<li>{{ item }}</li>
{% endfor %}
</ul>
<button onclick="Place( {{ a[0] }} );">Place order</button>
<hr>
Uno R3
- Uno R3
- 使用USB
- 微辊
下单
页面上有几个相同的id?你是认真的吗?我的坏朋友,我看了一下。将id
换成类
。没什么大不了的。@Nathan我不明白。页面上有几个相同的id?你是认真的吗?我的坏朋友,我看了一下。将id
换成类
。没什么大不了的。@Nathan我没听明白。你能提供一个例子说明ard
的内容吗?@ClaudioBusatto它包含字符串。当你使用for in
对字符串进行迭代时,每次迭代都将一个字符串作为当前项。看看这个简短的例子:@ClaudioBusatto实际上是从表中复制了一组行。您的问题是否只与按钮中的onclick
操作有关?我的意思是,列表在屏幕上呈现得好吗?你能提供一个样本说明ard
的内容吗?@ClaudioBusatto它包含字符串。当你使用for in
对字符串进行迭代时,每次迭代都将一个字符串作为当前项。看看这个简短的例子:@ClaudioBusatto实际上是从表中复制了一组行。您的问题是否只与按钮中的onclick
操作有关?我的意思是,列表在屏幕上呈现得好吗?