JQuery change clone inputs to empty

折月煮酒 提交于 2019-12-07 22:57:16

问题


I am trying to clone a class that contains inputs and textareas, and turn their values to nothing.

var current = $(".item").last();

  current.clone().insertAfter( current );
  current.find('input,textarea').val('');

The problem is instead of clearing the cloned objects inputs and textareas, it clears the last class inputs and textareas before that.


回答1:


Your code is modifying the current objects, not the cloned ones. Try something like this:

var current = $(".item").last();

var cloned = current.clone();
cloned.find('input,textarea').val('');
cloned.insertAfter( current );


来源:https://stackoverflow.com/questions/10308621/jquery-change-clone-inputs-to-empty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!