克隆对象中的清除文本字段值
我无法清除从 jQuery clone 函数创建的文本字段值。 我只是复制 add_new_content 内容并附加最后一个 add_new_content 元素。它效果很好。但以防万一,在文本字段中输入一些文本后单击 add_new_box 意味着。它克隆输入值。但我想要新的文本字段。
标记
<div class="add_new_content">
<div class="add_new_box">ADD NEW</div>
<input type="text" value="" />
</div>
脚本
$(document).ready(function(){
$(".add_new_box").live('click',function(){
$('.add_new_content:last').clone().appendTo('.add_new_content:last');
});
});
工作示例是这里
我该怎么做。
I am having trouble to clear text field value created from jQuery clone function.
I am just copying add_new_content content and appending that one with last add_new_content element.it works good.But in case, clicking add_new_box after enter some text in the text fields means. it clones with input value.but i want fresh text field.
Mark up
<div class="add_new_content">
<div class="add_new_box">ADD NEW</div>
<input type="text" value="" />
</div>
Script
$(document).ready(function(){
$(".add_new_box").live('click',function(){
$('.add_new_content:last').clone().appendTo('.add_new_content:last');
});
});
Working Example is Here
How can i do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将克隆的
元素与 find() 进行匹配,并使用 val() 重置其值:
You can match the cloned
<input>
element with find() and reset its value with val():在克隆之前或之后设置该值。
set the value right before, or after, you clone it.
克隆后删除该值,例如。
remove the value after you clone it eg.