简体   繁体   English

使用javascript拖放

[英]Drag And Drop using javascript

i have to display google images in my website. 我必须在我的网站上显示Google图片。 i would like to add google images in my wishlist simply drag the image into dropbox. 我想在我的收藏谷歌图片只需拖动图片到Dropbox的。 it will add into my wishlist. 它将添加到我的愿望清单中。 for this i am using this code. 为此,我正在使用此代码。 this code is from mozilla 这段代码来自mozilla

but it is not working in IE,CROME. 但它在IE,CROME中不起作用。 is there any chance to compatible. 有没有机会兼容。 otherwise is there any another chance to solve this problem? 否则还有其他机会解决这个问题吗?

actually i was used ninja drag-drop image code also. 实际上我也曾用过忍者拖放图像代码。 but it is not working properly for google images which displayed in my website. 但对于显示在我的网站中的Google图片,它无法正常工作。

actually i am displaying google images using google api in my website. 实际上,我在我的网站上使用google api显示google图像。 in my web page at below of this google results there is a dropbox which is like in the above url( mozilla ). 在此google结果下方的我的网页中,有一个类似上面url( mozilla )的保管箱。 if i would like to add any image from the google results simply i have to drag the google image into dropbox. 如果我想从google结果中添加任何图像,只需要将google图像拖到Dropbox中即可。

Try this 尝试这个

  function drop(evt) {
        evt.stopPropagation();
        evt.preventDefault(); 
        var imageUrl = evt.dataTransfer.getData('text/html');

        var rex = /src="?([^"\s]+)"?\s*/;
        var url, res;

        url = rex.exec(imageUrl);

        var dropped=document.getElementById('dropped');

        var img = document.createElement('img');
        img.setAttribute('src',url[1]);
        dropped.appendChild(img);
}

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM