Strore div进入数据库

时间:2017-11-20 19:01:55

标签: javascript php jquery

我创建了一个带有div标签的电路板,我希望在丢弃图像后将div(电路板)带到另一个页面,图像隐藏在我放置的相同位置

<html>
<div id='grid' name="grid">
  <div class='row'>
    <div id='cell0' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell1' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell2' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell3' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell4' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell5' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell6' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell7' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell8' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <div id='cell9' class='cell' ondrop="drop(event)" ondragover="allowDrop(event)"></div>
  </div>

</html>

function allowDrop(ev) {
  ev.preventDefault();
}
window.allowDrop = function(ev) {
  ev.preventDefault();
  if (ev.target.getAttribute("draggable") == "true")
    ev.dataTransfer.dropEffect = "none"; // dropping is not allowed

  else
    ev.dataTransfer.dropEffect = "all"; // drop it like it's hot
};

1 个答案:

答案 0 :(得分:0)

如果您只想将div的ID存储到数据库中,它应该可以从事件目标中调用它

function drop(e) {
    // assuming e.target is the div
    e.preventDefault();
    alert(e.target.id); //store into DB
}

如果要保存放入数据库中div的图像,请按照以下文章操作: https://www.w3schools.com/HTML/html5_draganddrop.asp

一个提示:你不应该存储图像,而是它的路径。所以你要把路径设置为数据