如果比较条件,如何在twig中获取id属性值

时间:2017-08-08 11:54:21

标签: javascript html twig

使用twig Html语言

<select id="input-custom-field{{ custom_field.custom_field_id }}" onchange="{% if this.id == 'input-custom-field1' %} myFun(){% endif %}" >

以上行是在Twig html中。如何在if条件下获取id属性的值?您可能会看到我已经设置了id值input-custom-field {{custom_field.custom_field_id}},它返回&#34; input-custom-field1&#34;。我想在if语句中将此值用作左字符串,因为如果此语句返回true,则在onchange中指定myFun()。

1 个答案:

答案 0 :(得分:0)

您拥有所有数据。您可以在条件

中使用custom_field.custom_field_id作为左侧值
<select id="input-custom-field{{ custom_field.custom_field_id }}" onchange="{% if custom_field.custom_field_id == 1 %} myFun(){% endif %}" >