且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

拖放:如果图像是链接(不是链接的URL),如何获取图像的URL

更新时间:2023-02-26 13:05:47

我认为这是有效的:

http://fiddle.jshell。 net / 4E92W / 3 /

使用jQuery。
(我只是用它来获取src属性所以我认为你可以不用它)

Using jQuery. (I'm just using it to get the "src" attribute so i think you can do without it)

我换了:

var imageUrl = evt.dataTransfer.getData('URL');

使用:

var imageUrl = evt.dataTransfer.getData('text/html');

哦,我用console.log替换警报,所以你需要打开它。

Oh, and I replace the alert with a console.log so you'll need to open it.

编辑:它不适用于Firefox。

It's not working with Firefox.

Edit2:这个似乎适用于两个浏览器: http://fiddle.jshell.net/4E92W/5/

Edit2 : This one seems to work with both browser : http://fiddle.jshell.net/4E92W/5/