Changing input name using JQUERY

后端 未结 2 1853
眼角桃花
眼角桃花 2021-02-05 17:26

I\'m trying to change all the input name based on the list index of

  • but it seems like it\'s not changing at all.

    $(\'.test\').click(funct         
    
    
            
  • 相关标签:
    2条回答
    • 2021-02-05 17:50
      $("li.songs").each(function(i) {
        $(this).find('input').attr('name', 'song' + i);
      });
      
      0 讨论(0)
    • 2021-02-05 18:00

      You are cloning the object, so the change is done to a copy rather than the original DOM node.

      Don't use clone() and you'll be fine. Or do this:

      $("li.songs input").each(function(i) {
        $(this).attr('name', $(this).attr('name') + i);
      });
      
      0 讨论(0)
    提交回复
    热议问题