チェックするコードの断片はFF、Chrome、Safariで正常に機能しますが、jQueryクローン関数を実行する場合はIEに問題があるようです。
私のテンプレート:
<form method="post" action="/post/add/">
{{ form.management_form }}
<div class='table'>
<table class='no_error'>
<input id="id_mypost_set-0-title" type="text" name="mypost_set-0-title" />
<input id="id_mypost_set-0-content" type="text" name="mypost_set-0-content" />
</table>
</div>
<input type="button" value="Add Other" id="add_more">
<script>
$('#add_more').click(function() {
cloneMore('div.table:last', 'mypost_set');
});
</script>
</form>
javascriptファイルの場合:
function cloneMore(selector, type) {
var newElement = $(selector).clone(true);
var total = $('#id_' + type + '-TOTAL_FORMS').val();
newElement.find(':input').each(function() {
var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
var id = 'id_' + name;
$(this).attr({'name': name, 'id': id}).val('').removeAttr('checked');
});
newElement.find('label').each(function() {
var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
$(this).attr('for', newFor);
});
total++;
$('#id_' + type + '-TOTAL_FORMS').val(total);
$(selector).after(newElement);
}
問題はセレクターにあります:「元のhtmlコードのクローンは正常に機能します」が、クローンされたコードからのクローンはセレクターを「未定義」としてマークします。つまり、2回目にテーブルをクローンします。これらの複製されたアイテムに対して、セレクターは機能しなくなります。
IEでのみ問題が発生します。
何が欠けていますか?ヒントはありがたいです:)