admin管理员组文章数量:1291327
I have a div in my website, and when it's clicked upon, it reveals the search box (done with jQuery).
However, I would like this div to accept drag'n'dropped text. In my use case, a user selects regular text from anywhere on the site, and drag'n'drops it to copy-paste it into the search box.
If the search box was always visible, he could simply drop it into the text box, handled natively by the browser/OS. However, is there a way I could simulate the same thing with this div? The user would drop his text onto the div, and it would fire the click event to show the text box and paste the dropped text into the box.
My website is uses Modernizr+jQuery+jQuery UI and HTML5/CSS3. IE6 patibility is a non-issue.
Thank you in advance!
I have a div in my website, and when it's clicked upon, it reveals the search box (done with jQuery).
However, I would like this div to accept drag'n'dropped text. In my use case, a user selects regular text from anywhere on the site, and drag'n'drops it to copy-paste it into the search box.
If the search box was always visible, he could simply drop it into the text box, handled natively by the browser/OS. However, is there a way I could simulate the same thing with this div? The user would drop his text onto the div, and it would fire the click event to show the text box and paste the dropped text into the box.
My website is uses Modernizr+jQuery+jQuery UI and HTML5/CSS3. IE6 patibility is a non-issue.
Thank you in advance!
Share Improve this question edited Sep 24, 2011 at 17:38 Saket 46.2k13 gold badges63 silver badges80 bronze badges asked Sep 24, 2011 at 17:09 Emphram StavangerEmphram Stavanger 4,2149 gold badges38 silver badges66 bronze badges 3- This question covers a similar topic. – Rusty Fausak Commented Sep 24, 2011 at 17:16
- I saw that topic, but it requires the dragged text to be in a specific container which is then made draggable(), whereas I'm talking about any old regular text you highlight and drag. I already tried applying droppable() to the div, and the drop event doesn't seem to fire. – Emphram Stavanger Commented Sep 24, 2011 at 17:21
-
Perhaps using a bination of
mouseover
,mouseup
anddocument.getSelection
would work. See stackoverflow./questions/1317727/… – Rusty Fausak Commented Sep 24, 2011 at 17:25
1 Answer
Reset to default 8You can use the HTML5 Drag and Drop events:
$('#dropTextHere').bind('drop', function (e) {
var theDroppedText = e.originalEvent.dataTransfer.getData('Text');
});
You can read more about it here.
本文标签: javascriptDragdrop text over DIV Stack Overflow
版权声明:本文标题:javascript - Drag-drop text over DIV- Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741530454a2383725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论