Javascript 为什么来自动态添加输入的输入名称的最近索引不起作用?
我有一个表单,我有动态添加的输入,我有动态添加的每个输入的变更索引 这是我的html表单Javascript 为什么来自动态添加输入的输入名称的最近索引不起作用?,javascript,php,jquery,html,dynamic,Javascript,Php,Jquery,Html,Dynamic,我有一个表单,我有动态添加的输入,我有动态添加的每个输入的变更索引 这是我的html表单 $(函数(){ var hobiesIndex=1; $(“#添加_字段”)。单击(函数(){ $(this).closest('tr').find('input.hobies').attr('name'),“hobies['”+hobiesIndex+“')”); $(“#table_container”).append($(“#temp_div”).html()); hobiesIndex++; })
$(函数(){
var hobiesIndex=1;
$(“#添加_字段”)。单击(函数(){
$(this).closest('tr').find('input.hobies').attr('name'),“hobies['”+hobiesIndex+“')”);
$(“#table_container”).append($(“#temp_div”).html());
hobiesIndex++;
});
})
我的恐惧
形象
+添加更多
针对每次单击中的最后一次输入
:
改变
$(this).closest('tr').find('input.hobies').attr('name', "hobies['"+hobiesIndex+"']");
到
你们想要什么,发生了什么?谢谢你们的回答,这正是我想要的,我不知道什么时候我想用它last@Sai,非常欢迎。选择器没有在代码中针对正确的元素。。。。。
$('input.hobies').last().attr('name', "hobies["+hobiesIndex+"]");