当然,当你拖动图像taxe区将消失,在文本区域中,您将获得拖动图像的URL(在某些浏览器中,图像将在新选项卡中打开)。
如果你想在拖动的地方显示图像,你的taxtarea透明背景div。并设置文本区域:
#div1{width: 150px; height:150px; position:relative; border:1px solid;}
textarea{
position:absolut;
width:100%;
height:100%;
opacity: 0;
left:0;
top:0;
}
#div1 img{width: 100%;height:100%;}
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<div id="div1"><img /> <textarea></textarea></div>
<img src="https://www.gravatar.com/avatar/087039a00851e75ff483470e3aba89c9?s=48&d=identicon&r=PG" />
<script>
$('textarea').on("drop", function()
{
var $this = $(this);
setTimeout(function()
{
$($this).prev().attr('src', $this.val());
$this.parent().css('border', '1px solid');
}, 200);
});
$("textarea").bind("dragover", function()
{
$(this).parent().css('border', '2px dashed red');
});
$('textarea').bind('dragleave', function()
{
$(this).parent().css('border', '1px solid');
});
</script>
我认为(但不知道)数据传递是拖从Windows到浏览器中的文件?例如在选择文件中上传。 –
https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop – user123456
链接页面中的文本区域在哪里? –