开发者

Generating html code for drag and drop

I want to provide an user开发者_开发问答 of my application with a drag and drop feature. Say I have a div container where the user can drag and drop images present within the div to anywhere within the div. Something similar to http://threedubmedia.com/code/event/drag/demo/basic. But what I need is after the drag and drop has been completed, I want to extract the html code of the container div, so that I can store it and show it to the user at a later point of time, or use it elsewhere for some other purpose. There are a lot of jquery plugins for drag and drop, but I couldnt find any to generate the html code for the dragged elements. What could be the most straightforward way of doing it? Thanks in advance.


Well it's fairly straightforward to extract the contents of a div with javascript. If you're already using jquery you can simply do something like:

var contents = $('#draggedDiv').html();

or for regular javascript:

var contents = document.getElementById('draggedDiv').innerHTML;

Is this what you mean?


The easiest way I know is with JavaScript, by storing the innerHTML of the dragged div in a JS variable.

var dragDiv;
dragDiv = getRefToDiv( 'drag-div-id' ).innerHTML;
...

<body>
<div id="drag-div-id">
<!-- the div's contents -->
</div>
</body>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜