[英]Can you trigger some type of event with drag and drop boxes?
I'm trying to develop a small site where user can drag and drop pictures. 我正在尝试开发一个小型站点,用户可以在其中拖放图片。 So when user drags a particular picture to the box it would return some kind of a result in the form of text like details about that picture... 因此,当用户将特定图片拖到框中时,它将以文本形式返回某种结果,例如有关该图片的详细信息...
This is the current code that I'm using to accomplish drag and drop, but I can't figure out how to add functionality that I described above: 这是我用来完成拖放操作的当前代码,但是我不知道如何添加上面描述的功能:
<!DOCTYPE HTML>
<html>
<head>
<meta charset ="utf-8">
<style type="text/css">
#dragBox {width:336px;height:221px;padding:10px;border:1px solid #aaaaaa;}
</style>
<script>
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body bgcolor="#333333">
<div div align="center">
<img id="drag1" src="foodOne.jpg" draggable="true" ondragstart="drag(event)" width="336" height="221">
<div id="dragBox" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
</body>
</html>
A drop event can have a files
property. 放置事件可以具有files
属性。 You can read the files with JavaScript. 您可以使用JavaScript读取文件。 The common approach is to send it to the server which can then send the information back, like a path to a thumbnail. 常见的方法是将其发送到服务器,然后服务器可以将信息发送回来,例如缩略图的路径。
There are a lot of scripts readily available already, just Google/Bing. 已经有很多脚本可供使用,仅Google / Bing。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.