jQuery将克隆输入更改为空 [英] JQuery change clone inputs to empty
本文介绍了jQuery将克隆输入更改为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试克隆一个包含输入和文本区域的类,并将它们的值变为空.
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.
推荐答案
您的代码正在修改current
对象,而不是克隆的对象.尝试这样的事情:
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 );
这篇关于jQuery将克隆输入更改为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文