问题
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