lirongfei123
9/20/2016 - 6:50 AM

复制html标签属性

function cloneImg (elem) {
		var imgNode = document.createElement("div");
		var attributes = elem.attributes;
		for (var i in attributes) {
			if(!attributes.hasOwnProperty(i)) {
				continue;
			}
			var attr = attributes[i];
			if(attr.name == 'class') {
				imgNode.className = attr.value;
				continue;
			}
			imgNode.setAttribute(attr.name, attr.value);
		}
		return imgNode;
	}