我遵循了互联网上的拖放教程,使用 js 函数:
function dragUser(user, event) {
event.dataTransfer.setData('User', user.id);
}
function dropUser(target, event) {
var user = event.dataTransfer.getData('User');
target.appendChild(document.getElementById(user));
}
以及我修改成的 div/id/elements:
<div id="unassigned" ondrop="dropUser(this, event)" ondragenter="return false" ondragover="return false">
Names:
<a draggable="true" class="user" id="banana" ondragstart="dragUser(this, event)">Banana</a>
<a draggable="true" class="user" id="newyork" ondragstart="dragUser(this, event)">New York</a>
<a draggable="true" class="user" id="london" ondragstart="dragUser(this, event)">London</a>
<a draggable="true" class="user" id="ant" ondragstart="dragUser(this, event)">Ant</a>
<a draggable="true" class="user" id="melon" ondragstart="dragUser(this, event)">Melon</a>
<a draggable="true" class="user" id="cow" ondragstart="dragUser(this, event)">Cow</a>
</div>
<div id="fruit" ondrop="dropUser(this, event)" ondragenter="return false" ondragover="return false">
Fruit
</div>
<div id="animal" ondrop="dropUser(this, event)" ondragenter="return false" ondragover="return false">
Animal
</div>
<div id="city" ondrop="dropUser(this, event)" ondragenter="return false" ondragover="return false">
City
</div>
现场演示我在这里放了 jsfiddle --> http://jsfiddle.net/skinnytotoro/njdyJ/1/
现在我想在排序/拖放匹配正确时添加一个警报(例如,名称属于正确的类别)会有一个警报说“所有匹配。Welldone!:)”(在表格下方或周围盒子)
或者当一个或一些名字属于错误的类别时,还有一个警报显示文本警告,如“几乎正确。继续尝试!”
问题是..我必须添加什么代码或js函数来实现它?(警觉的东西)