Jquery 对象没有';t支持方法'的属性;克隆';
我在尝试克隆HTML的特定部分时遇到问题 我有一个复制按钮,可以复制添加的最后一个元素,例如,一个div包含一个输入框,如果他们想添加另一个,或者他们有太多的事情要做,就复制它 除了InternetExplorer(所有版本均为8以上)之外,这似乎在所有浏览器上都能正常工作 我不断得到错误对象不支持属性或方法“克隆” 首先,我必须将按钮的点击事件发送到函数“添加另一个”中,因为可能存在多个“添加另一个”按钮的情况,并且我必须以最接近的父项为目标Jquery 对象没有';t支持方法'的属性;克隆';,jquery,internet-explorer,button,copy,clone,Jquery,Internet Explorer,Button,Copy,Clone,我在尝试克隆HTML的特定部分时遇到问题 我有一个复制按钮,可以复制添加的最后一个元素,例如,一个div包含一个输入框,如果他们想添加另一个,或者他们有太多的事情要做,就复制它 除了InternetExplorer(所有版本均为8以上)之外,这似乎在所有浏览器上都能正常工作 我不断得到错误对象不支持属性或方法“克隆” 首先,我必须将按钮的点击事件发送到函数“添加另一个”中,因为可能存在多个“添加另一个”按钮的情况,并且我必须以最接近的父项为目标 $('p.add_another').unbind
$('p.add_another').unbind('click').click(function(e){
e.preventDefault();
var next = $(this).closest('.option').find('.repeat_block:last').find('p input[type="checkbox"]').attr('name');
next = next.replace(/elements\[[A-Za-z0-9\_]+\]\[[A-Za-z0-9\_]+\]\[([0-9]+)\]/, '$1');
add_another_repeat($(this),next);
return false;
});
而add_是另一个函数
function add_another_repeat(ev,i) {
//alert('I: '+i);
parent = ev.closest('.option').find('.repeat_block:last');
// make copy and add to DOM
var add = parent.clone();
parent.after(add);
// increment the array keys
var r = add.find('p input[type="checkbox"]').attr('name'),
pattern = '\['+i+'\]',
regex = new RegExp(pattern,'g'),
next = parseInt(i)+1;
add.find('p input[type="checkbox"]').attr('name', r.replace(regex, next));
add.find('input,textarea,select').each(function(){
r = $(this).attr('name');
pattern = '\['+i+'\]',
regex = new RegExp(pattern,'g');
$(this).attr('name', r.replace(regex, next));
//$(this).val('');
r = $(this).attr('id');
pattern = '\_'+i;
regex = new RegExp(pattern, 'g');
$(this).attr('id', r.replace(regex, '_'+next));
});
$('p.add_another button').unbind('click').click(function(){
add_another_repeat($(this),next);
return false;
});
// tidy up the first elements
//parent.find('h3 input[type="checkbox"]').attr('checked', 'checked'); //.attr('disabled', true);
parent.find('p.add_another').remove();
return false;
}
错误似乎出现在这一行var add=parent.clone()代码>但仅在上,即仅在
是否有人对可能出现的问题提出了一些建议,因为我已经没有想法了如果您将parent
登录到控制台,它是有值还是未定义
?如果它有一个值,那么长度是否大于等于1?它只是表示JSFIDLE方法的[object Window]时间:)parent=ev.closest('.option')。find('.repeat_block:last')代码>如果我添加.html()并在父级上进行控制台登录,我也可以输出所需的html。但即使是var add=parent.html();在IE对象不支持属性或方法“html”时引发相同错误??