When I click a button I'm trying to know what checkbox
is selected.
(当我单击一个按钮时,我试图知道checkbox
哪个checkbox
。)
The problem is that the checkboxes are created dynamically with a for loop
in my template. (问题是复选框是在模板中动态创建的,带有for loop
。)
html
(html)
<form action="#" method="post" target="#">
{% for node in Last_val_nodes %}
<input type="checkbox" class="nodeRuta" name="{{node.0}}">{{node.0}}<br>
{% endfor %}
</form>
JS
(JS)
$('#filtrar_btn_map').click(function(){
if( $(".nodeRuta").is(':checked') ) {
var node = $(".nodeRuta").attr("name");
alert(node);
}
});
Last_val_nodes
is a list like [['node1',1,2],['node2',4,5],['node3',7,8]]
and with my code the alert
is always showing node1
, whatever checkbox is selected.
(Last_val_nodes
是一个类似于[['node1',1,2],['node2',4,5],['node3',7,8]]
,使用我的代码, alert
始终显示node1
,无论复选框是已选择。)
I tried with var node = $(this).attr("name");
(我尝试使用var node = $(this).attr("name");
)
but it's not working too. (但它也不起作用。)
Can somebody help me, please? (有人可以帮我吗?)
Thank you very much.
(非常感谢你。)
ask by NEA translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…