我想更改元素被拖动到的 div 的背景。
我还设置了一个计数器,当有东西被拖过它时它会更新(在我的例子中它是我桌面上的一个文件)。柜台部分工作正常,但背景颜色没有改变。我做错了什么?
var drop = document.getElementById('drop1');
// Tells the browser that we *can* drop on this target
addEventHandler(drop, 'dragover', function (e) {
e = e || window.event; // get window.event if e argument missing (in IE)
if (e.preventDefault) {
e.preventDefault();
}
fileNumber = fileNumber + 1;
status.innerHTML = fileNumber;
$("#drop1").css("background-color",'#AA0000');
//$('drop1').css('background-color', '#AA0000');
return true;
});
html 看起来像这样
<DIV id="drop1">Drop files here
<h1 align=center>A File Preview Demo</h1>
<DIV id="status">Drag the files from a folder to a selected area ...</DIV>
<DIV id="drop2">Drop files here.</DIV>
<DIV id="list"></DIV>
<DIV id="list2"></DIV>
</DIV>
最佳答案
关于javascript - 在 dragover 上更改 div 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19845217/