douge7771 2016-01-27 12:44
浏览 33

无法在javascript变量中存储html div

This is how it currently appears

I have a game which requires a specific tile to be placed in a specific holder.

<div id="tile_holder1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>

<!--This allows the object to be dragged--><!--need to set draggable to true to enable the object to be dragged -->
<div id = "drag1" draggable="true"  ondragstart="drag(event)" width="336" height="69">

<!--This creates the object to be dragged-->
<button id = "tile1">Place a Square on to the ground to start to build your house</button></div>

So i want the object named tile1 to be dragged and dropped in tile_holder1. Im currently using Javascript and struggling how to correctly go about it. I want to store the required HTML divs within javascript variables and be able to use an IF statement to make sure the tile is in correct holder. I'm very new to Javascript and can't find a way to do it.

Ive created a function that will be processed on the play button been pressed. Any help would be great.

<button onclick="myFunction()" id = "play">Play Me</button>
<h1 id = "demo"></h1>
<script>
    function myFunction() {
        var message;
        var test = document.getElementById('tile_holder1').innerHTML;
        var test2 = document.getElementById('tile1').innerHTML;
        if (//I want to be able to check that test2 is matched with correctly with test and if so display a message) {
            message = "Good";
            document.getElementById("demo").innerHTML = message;
        };
    }
</script>

Or would it be easier to use another programming language,possibly PHP?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 vscode的问题提问
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM