作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现了很多不同的拖放实现,但它们似乎都是在图像没有嵌套在 标记内的一般假设下运行的。
无论是浏览器、mac os 还是 windows,结果总是一样的:
< img src='http://www.lol.com/pic.jpg' />
http://www.lol.com/pic.jpg
以 html 形式。或者,如果拖入桌面 - 它将保存实际图像。< a href='http://www.lol.com/notgonnahappen.html'>< img src='http://www.lol.com/pic.jpg' />< /a>
http://www.lol.com/notgonnahappen.html
如果在桌面上拖动,则创建一个 URL 链接。最佳答案
var data = $(e.dataTransfer.getData('text/html'));
var img = data.attr('src');
if (!img)
img = data.find("img").attr('src');
我是一名优秀的程序员,十分优秀!