清除克隆对象中的文本字段值 [英] clear text field value in clone object

查看:103
本文介绍了清除克隆对象中的文本字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法清除通过jQuery clone 函数创建的文本字段值. 我只是复制 add_new_content 内容,并将其附加到最后一个add_new_content元素.它的效果很好.但是,以防万一,请在文本字段中输入一些文本后单击add_new_box即可.它会使用输入值进行克隆.但是我想要新鲜的文本字段.

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.

标记

<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');

});

});

工作示例为此处

我该怎么做.

推荐答案

您可以将克隆的<input>元素与 find(),然后使用 val()

You can match the cloned <input> element with find() and reset its value with val():

$('.add_new_content:last').clone()
                          .find("input:text").val("").end()
                          .appendTo('.add_new_content:last');

这篇关于清除克隆对象中的文本字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆