Jquery克隆执行问题

我有以下代码工作正常,除了一些延迟。 当第一次在浏览器(IE9)中打开应用程序然后立即点击addAnotherCard按钮时,它没有立即响应。 它至少需要8-10秒。我暂停10秒并尝试点击然后它工作。

我还观察到,我点击了大约4次直到它克隆,然后我已经validation了cosole.log并且vriables正在增加到6但是克隆只在屏幕上显示一次。 点击之后,我可以看到每个部分和控制台日志为7,8,9等。所以我的初始点击(1,2,3,4和5)都消失了。

这是原始代码和之前的post,包括JSFiddle。

$('#AddCC').click(function () { uniqueId++; var container = $("#CCcontainer"), hidden = $("#hiddenStoredPanelsArray"), storedPanels = hidden.length ? $.parseJSON(hidden.val()) : null, copyDiv = $("#CCPanel").clone(), divID = "CCPanel" + uniqueId, removeID = "RemoveCard" + uniqueId; console.log(storedPanels); storedPanels.push(uniqueId); hidden.val(JSON.stringify(storedPanels)); console.log(storedPanels); copyDiv.attr('id', divID); container.append(copyDiv); container.append("
"); $('#' + divID).find('input,select').each(function () { $(this).attr('id', $(this).attr('id') + uniqueId); }); $("#" + removeID).find("button").on("click", function () { var id = parseInt($(this).attr("id").replace("btnRemoveCard", "")), hidden = $("#hiddenStoredPanelsArray"), storedPanels = hidden.length ? $.parseJSON(hidden.val()) : null, index = storedPanels == null ? -1 : storedPanels.indexOf(id); console.log(storedPanels); if (index > -1) storedPanels.splice(index, 1); console.log(storedPanels); container.find("div[id$='" + id.toString() + "']").remove(); hidden.val(JSON.stringify(storedPanels)); }); });

DEMO

如何查找父div的属性

有人可以帮忙吗? 谢谢!

下面的代码解决了这个问题。

 if(!(window.console && console.log)) { console = { log: function(){}, debug: function(){}, info: function(){}, warn: function(){}, error: function(){} }; }