I have a problem in javascript (drag and drop).
// I drag: <div id = "name">Name</div>
<div class="color">white</div>
<div class="color">black</div>
<div class="color">pink</div>
//And drop here:
<div class="color">yellow</div>
<div class="color">green</div>
<div class="color">red</div>
//result:
<div class="color">white</div>
<div class="color">black</div>
<div class="color">pink</div>
<div id="name">
<div class="color">yellow</div>
<div class="color">green</div>
<div class="color">red</div>
</div>
//continue drag:<div id = "name">Name</div> other and drop above: <div class="color">green</div>
<div class="color">white</div>
<div class="color">black</div>
<div class="color">pink</div>
<div id="name">
<div class="color">yellow</div>
</div>
<div id ="name">
<div class="color">green</div>
<div class="color">red</div>
</div>
我的代码示例如下:
function addDrag(obj,kind){
addEvent(obj, 'dragstart', function (e) {
dragSrcEl = obj;
e.dataTransfer.setData('text/html', obj.innerHTML);
});
addEvent(obj, 'dragover', function (e) {
if (e.preventDefault) e.preventDefault(); // allows us to drop
$(obj).addClass('dragover');
e.dataTransfer.dropEffect = 'copy';
return false;
});
..........
问题在于当我将“Name”下的任何位置,class="color"拖放到“Name”的子级下时......“Name”是父级。该如何编写代码!请帮助我!