gpt4 book ai didi

javascript - jQuery clone() 问题 : clone input without value

转载 作者:行者123 更新时间:2023-11-29 18:32:03 26 4
gpt4 key购买 nike

我正在使用 jquery .clone(),它工作正常。但是我的问题是,当我克隆我的输入字段时,它也会克隆前一个字段的值。我不想克隆该值。我该如何克服这个问题?

这是我的代码

function addrow(){
var num = $('.clonedInput').length;
var newNum = new Number(num + 1);
var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
$('#input' + num).after(newElem);

jQuery('.clonedInput').each(function(){
jQuery('#total', jQuery(this)).unbind('blur');
});

var ci = jQuery('.clonedInput:last');
jQuery('#total', ci).blur(function() {
addrow();
});
}

问候,

费赞

最佳答案

试试这个:

var newElem = $('#input' + num).clone().attr('id', 'input' + newNum).val('');

关于javascript - jQuery clone() 问题 : clone input without value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7120358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com