我想在每次将项目拖入可拖动区域时进行计数,并在每次发生时增加输入字段内的计数器。
这是我现在所拥有的:
function cancel(e) {
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
var dragItems = document.querySelectorAll('[draggable=true]');
for (var i = 0; i < dragItems.length; i++) {
addEvent(dragItems[i], 'dragstart', function (event) {
// store the ID of the element, and collect it on the drop later on
event.dataTransfer.setData('Text', this.alt);
});
}
var drop = document.querySelector('.drop-items');
var droplist = document.querySelector('.items-listed-rc');
// Tells the browser that we *can* drop on this target
addEvent(drop, 'dragover', cancel);
addEvent(drop, 'dragenter', cancel);
addEvent(drop, 'drop', function (e) {
if (e.preventDefault) e.preventDefault(); // stops the browser from redirecting off to the text.
this.innerHTML += '<p>' + e.dataTransfer.getData('Text') + '<input type="text" class="counter-items"></p>';
return false;
return false;
});
这是小提琴: