HTML の特定のセクションを複製しようとすると問題が発生します。
追加された最後の要素を複製する複製ボタンがあります。たとえば、divには入力ボックスが含まれており、別の要素を追加したい場合、または追加したい場合は複製します。
これは、Internet Explorer (8 以降のすべてのバージョン) を除くすべてのブラウザーで問題なく動作するようです。
Object does not support property or method 'clone'というエラーが表示され続けます
最初に、ボタンのクリック イベントを関数 'add_another_repeat' に送信する必要があります。これは、複数の add_another ボタンがあり、最も近い親をターゲットにする必要がある場合があるためです。
$('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_another 関数
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;
}
エラーはこの行に表示されるようですが、 IE のみvar add = parent.clone();
でのみ表示されます
アイデアが不足しているため、何がうまくいかないのかについて誰か提案がありますか