我正在尝试用纯 Javascript 克隆一个 div,但是,cloneNode 会导致重复的 id (div_0)。我想将 id 增加为 div_1, div_2... 并对 somevar = {'elem', 'div_1'} 执行相同操作...谢谢
<html>
<head></head>
<body>
<div id="mydiv">
<div id="div_0">
<script type="text/javascript">
<!--
somevar = {'elem', 'div_0'};
//-->
</script>
<p>HELLO</p>
</div>
</div>
<a href="#" onclick="cloning()">CLONE</a>
<script type="text/javascript">
function cloning() {
var container = document.getElementById('mydiv');
var clone = document.getElementById('div_0').cloneNode(true);
container.appendChild (clone);
}
</script>
</body>
</html>