如何撤消 javascript 中的拖放操作?

How to undo a drag-and-drop in javascript?

在面向年幼儿童的页面上,他们必须在两个随机数之间拖放“<”、“=”或“>”这 3 个符号之一。此功能一次。

在向他们展示是否正确后,我想自动撤消拖放并显示 2 个新的随机数。这意味着将他们选择的标志送回原来的位置。像

WARNING FALSE CODE
move(document.getElementById("up3").innerHTML, document.getElementById("middle3").innerHTML);

我的“up3”和“middle3”是

类型的div
<div class="up3" id="up3"></div>

对应的类刚刚处理 定位、边框等。

On a page for young kids, they have to drag-and-drop one of the 3 signs "<", "=" or ">" between 2 random numbers. This functions once.

After showing them whether they've got it right, I would like to automatically undo the drag-and-drop and display 2 new random numbers. That means sending the sign they chose back to its original position. Something like...

我能想到3 ways做这个

  1. 硬重新加载页面:

    location.reload(true); // reload(false) reloads the browser cache
    window.location.reload();
    
  2. <div id="a">内的所有code/text转入<div id="b">

    document.getElementById("b").innerHTML = document.getElementById("a").innerHTML; // transfer code line
    document.getElementById("a").innerHTML = null;
    

    document.getElementById("b").innerHTML = document.getElementById("a").innerHTML; // transfer code line
    document.getElementById("a").innerHTML = "<div>Empty state code-block</div>";
    
  3. 最后(更简洁的方法)创建 reset() js 函数,当您需要时调用

    function reset(){
       document.querySelector("#answer-container").innerHTML = null;
       document.querySelector("#gt-container").innerHTML = ">";
       document.querySelector("#lt-container").innerHTML = "<";
       document.querySelector("#e-container").innerHTML = "=";
       document.querySelector("#gt-container").innerHTML = ">";
       // more code...
    }
    

我认为你应该re-state将你的问题更具体地表述一下,我不确定我的回答是否能得到你想要的结果。