简体   繁体   中英

Load div in a page without refresh whole of page

Hello I was make a experiment with DnD html5 and I need to make function who can bring back my div into formerly without refreshing a page.

This is my html,

<div class='panel panel-default' >
 <div class="canvas-wrap">
  <div id="canvastowr">
   <img src="<?php echo base_url()?>assets/images/tower_bg/sst3/tower2.png" draggable="false" width="450" height="460">
  </div>
  <div class="overcanvas" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
  <div class="mw-rf">
   //this img move into dive class overcanvas and I need to make them back
   <img id="mwdragable" src="<?php echo base_url()?>assets/images/mw.png" class="overmw" ondragstart="drag(event)" draggable="true" width="40" height="40" >
   <img id="rfdragable" src="<?php echo base_url()?>assets/images/rf.png" class="overrf" ondragstart="drag(event)" draggable="true" width="40" height="40" >
  </div>
 </div>
</div>

I was try load jquery, from this question. But didn't work for me. this is my button to refresh the div back into former, but not work.

document.getElementById('clear').addEventListener('click', function() {
 $('#canvas-wrap').load(document.URL +  ' #canvas-wrap');
}, false);

document.URL not work for me. then I must use what? please help me.

EDIT:

this is the screen shot: before I dropping the image, that is a fullscreen modal I need to drop the image to div rectangle whose overlaying the image tower. 下降之前

After I dropped the image : 在此处输入图片说明

I need to make that clear button. bring back the draggable image comeback into first position.

Try this:

document.getElementById('clear').addEventListener('click', function() {
 $('#canvas-wrap').load(window.location.href +  ' #canvas-wrap');
}, false); 

Use window.location.href for current URL

But this will only replace it with what's already there so what's the point?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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