使用您的代码,您可以使用cloneNode()方法在纯JavaScript中执行以下操作:
// Create a clone of element with id ddl_1:
let clone = document.querySelector('#ddl_1').cloneNode( true );
// Change the id attribute of the newly created element:
clone.setAttribute( 'id', newId );
// Append the newly created element on element p
document.querySelector('p').appendChild( clone );
或使用jQuery clone()方法(不是最有效的):
$('#ddl_1').clone().attr('id', newId).appendTo('p'); // append to where you want