49 lines
1.2 KiB
HTML
49 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Drag and Drop</title>
|
|
<style type="text/css">
|
|
#container {
|
|
width: 300px;
|
|
padding: 10px;
|
|
border: 1px solid darkgray;
|
|
}
|
|
#container > div {
|
|
padding: 25px;
|
|
border: 2px dashed lightgray;
|
|
color: darkgray;
|
|
text-align: center;
|
|
}
|
|
</style>
|
|
<script type="text/javascript">
|
|
function dragOver(ev) {
|
|
ev.preventDefault();
|
|
ev.dataTransfer.dropEffect = 'link';
|
|
}
|
|
function drop(ev) {
|
|
ev.preventDefault();
|
|
var files = ev.dataTransfer.files;
|
|
var output = [];
|
|
for (var file of files) {
|
|
output.push(
|
|
'<li><strong>',
|
|
escape(file.name),
|
|
'</strong> (',
|
|
file.type || 'n/a',
|
|
') - ',
|
|
file.size.toLocaleString(),
|
|
' bytes',
|
|
'</li>');
|
|
}
|
|
document.getElementById('filelist').innerHTML = output.join('');
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="container" ondrop="drop(event)" ondragover="dragOver(event)">
|
|
<div>将文件拖放至此处</div>
|
|
</div>
|
|
<ul id="filelist"></ul>
|
|
</body>
|
|
</html> |