javascript锦标赛支架拖放

时间:2015-06-12 13:46:53

标签: javascript jquery html jquery-ui

http://stockmarketsavant.com/catClicker

试图让支架拖放工作。什么是限制获胜者框中可以进入的好方法?

function drag(ev)
{
   console.log("drag()");
   ev.dataTransfer.clearData();
   ev.dataTransfer.setData("text", ev.target.id);
   ev.dataTransfer.setDragImage(ev.target,0,0);
   ev.dataTransfer.effectAllowed='move';
   return true;
}

function allowDrop(ev)
{
   console.log("allowDrop()");
   ev.preventDefault();
   return true;
}


function drop(ev)
{
   console.log("drop()");

   ev.preventDefault();
   var data = ev.dataTransfer.getData("text");
   ev.target.appendChild( document.getElementById(data).cloneNode(true));
   ev.target.src = document.getElementById(data).src;
}

这是HTML:

<div class="row">
  <div class="col-md-4  bracket_box" id="bracket-round1-1">
  <img id="bracket-1-img" src="static/images/goog.png" class=bracket_img draggable="true" ondragstart="drag(event)">
</div> </div>

<div class="row">
  <div class="col-md-4 col-md-offset-3 bracket_box" id="bracket-round1a-winner"  ondrop="drop(event)" ondragover="allowDrop(event)" ></div>
</div>

<div class="row">
  <div class="col-md-4 bracket_box" id="bracket-round1-2">
  <img id="bracket-2-img" src="static/images/appl.png" class=bracket_img draggable="true" ondragstart="drag(event)">
</div> </div>

0 个答案:

没有答案