body{ text-align .container{ display justify-content .colorBox{ width height border margin .showBox{ width height border margin .colorBox:nth-child(1){ background-color .colorBox:nth-child(2){ background-color .colorBox:nth-child(3){ background-color img{ border margin支持拖拽的元素需要开启拖拽的元素展示框 moveDom ; (e){ //防止浏览器默认行为(W3C) e.preventDefault(); } (){ (moveDom.src){ ; }else{ // 如果src没有值 那么 设置背景颜色 // console.log(moveDom); // console.log(window.getComputedStyle(moveDom).backgroundColor); window.getComputedStyle(moveDom).backgroundColor; } } ); ) { imgs[i].ondragstart = function (){ moveDom = this; } } ); ) { colorBoxs[i].ondragstart = function (){ moveDom = this; } }