jQuery克隆DOM节点
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%>b index div001div002div003
$(function() { $('#btn001').click(btn001Click); $('#btn002').click(btn002Click); initDiv();});function btn001Click() { // 这样会把id也克隆过来;这样clone()不会进行事件的拷贝; var $clone = $('#div001').clone(); // clone(false) == clone() // var $clone = $('#div001').clone(false); $('#div003').after($clone);}function btn002Click() { // 这样会把id也克隆过来;这样clone(true)会进行事件的拷贝; var $clone = $('#div001').clone(true); $('#div003').after($clone);}function initDiv() { $('div').click(function() { // 获取点击事件的DOM对象: arguments[0].target.id console.log('%c' + arguments[0].target.id + ' click', 'font-size:16px;color:red'); });}