jQuery jquery中的.clone()方法不复制值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12035910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.clone() method in jquery without copying value
提问by Carlos
Possible Duplicate:
Jquery clone of a textbox without the content
可能的重复:
没有内容的文本框的 Jquery 克隆
I use .clone
in jQuery. When I clone ul it is cloning its value also. I only want to copy structure not value. When you type some value in input field and then click clone it will clone input value too.
我.clone
在 jQuery 中使用。当我克隆 ul 时,它也在克隆它的值。我只想复制结构而不是值。当您在输入字段中键入一些值然后单击克隆时,它也会克隆输入值。
<div class="str">
<ul><li><input type="text" /></li></ul>
</div>
<a href="#">clone</a>
$(function() {
$('a').live('click', function() {
var cln = $('ul:last').clone();
$('.str').append(cln);
});
});
回答by VisioN
You can try the code below. By the way, if you use the last version of jQuery I'd suggest using on
method instead of live
(here instead of body
you can use any parent of a
element).
你可以试试下面的代码。顺便说一句,如果您使用最新版本的 jQuery,我建议您使用on
method 而不是live
(在这里body
您可以使用任何a
元素的父元素)。
$("body").on("click", "a", function() {
$("ul:last").clone().appendTo(".str").find("input[type='text']").val("");
});?