0

我需要将产品列表中的项目拖放到空白容器中。当用户完成拖放后,我必须将位置和使用的项目存储到数据库,以便我可以再次显示此配置。

不幸的是,我的问题从早期开始。我成功地将项目从列表拖放到容器,但不幸的是它们以表格形式显示,而不是在我分配给它们的坐标处

  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShoppingCart.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script src="scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var srcElement;

        $(document).ready(function () {

            $("div .product").each(function () {
                this.addEventListener('dragstart', OnDragStart, false);
            });

            $("div .bag").each(function () {
                this.addEventListener('dragenter', OnDragEnter, false);
                this.addEventListener('dragleave', OnDragLeave, false);
                this.addEventListener('dragover', OnDragOver, false);
                this.addEventListener('drop', OnDrop, false);
                this.addEventListener('dragend', OnDragEnd, false);
            });

        })

        function OnDragStart(event) {
            srcElement = this;

        }

        function OnDragOver(e) {
            e.preventDefault();


            return false;
        }

        function OnDragEnter(e) {
            e.preventDefault();
        }

        function OnDragLeave(e) {
            e.preventDefault();
        }

        function OnDrop(e) {
            e.preventDefault();

            var dm = srcElement.cloneNode(true);

            dm.style.Left = e.offsetX;
            dm.style.Top = e.offsetY;
            dm.style.position = "absolute";

            //$(this).append(srcElement);
            e.target.appendChild(dm); 

            e.stopPropagation();
            return false;
        }

        function OnDragEnd(e) {
            e.preventDefault();
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table >
                <tr>
                    <td>
                        <div draggable="true" id="div1" class="product">
                            <header>Rieker Trekkingsandalen braun</header>
                            <img src="images/monitor.jpg" style="height: 150px; width: 150px;" />
                        </div>
                    </td>
                    <td>
                        <div id="div2" class="product" draggable="true">
                            <header>Rieker Trekkingsandalen braun</header>
                            <img src="images/Cart.jpg" style="height: 150px; width: 150px;" />
                        </div>
                    </td>
                    <td>
                        <div id="div3" class="product" draggable="true">
                            <header>Rieker Trekkingsandalen braun</header>
                            <img src="images/mouse.jpg" style="height: 150px; width: 150px;" />
                        </div>
                    </td>
                    <td>
                        <div id="div4" class="product" draggable="true">
                            <header>Rieker Trekkingsandalen braun</header>
                            <img src="images/speaker.jpg" style="height: 150px; width: 150px;" />
                        </div>
                    </td>
                </tr>
            </table>

            <div class="bag">
            </div>
        </div>
    </form>
</body>
</html>

.product {
    height: 300px;
    width: 150px;
    border: 2px solid #666666;
    background-color: white;
    text-align: center;
    cursor: move;
}
.bag {
    background-color: green;
    height: 500px;
    width: 500px;
    position: absolute;
}

谁能指出我这里的问题?

干杯,斯特凡

4

1 回答 1

0
dm.style.position = "absolut";

应该

dm.style.position = "absolute";
于 2013-02-28T12:57:18.800 回答