SignalR Jquery自动生成Div

SignalR Jquery autogenerated Div

本文关键字:Div 自动生成 Jquery SignalR      更新时间:2024-02-05

我有这个代码,其中只有两个静态div,所以我希望你能帮助我在新用户到来时自动生成新的div。事实上,我在SignalR工作。我需要为新用户提供更多的div,每个用户都有自己的div。请提供任何CS或Jquery代码帮助来解决这个问题。谢谢你的帮助:)

我的索引。Html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style>
        body, html {
            margin: 0px;
            padding: 0px;
        }
        #indicator {
            width: 300px;
            height: 20px;
            background: lightgrey;
            color: black;
            position: absolute;
            left: 500px;
            top: 0px;
        }
        #myshape {
            width: 100px;
            height: 100px;
            background-color: blue;
            position: absolute;
            z-index: 100;
        }
        #yourshape {
            width: 100px;
            height: 100px;
            background-color: red;
            position: absolute;
            z-index: 1;
        }
    </style>
</head>
<body>
    <script src="Scripts/jquery-1.6.4.js"></script>
    <script src="Scripts/jquery-ui-1.10.3.js"></script>
    <script src="Scripts/jquery.signalR-2.0.0.js"></script>
    <script src="Scripts/jquery.signalR-2.0.0.min.js"></script>
    <script src="/signalr/hubs"></script>
    <script type="text/javascript">
        $(function () {
            $.connection.hub.start().done(function () {
                $("#indicator").html("connected");
                $("#myshape").draggable({
                    drag: function () {
                        var left = $("#myshape").offset().left;
                        var top = $("#myshape").offset().top;
                        $.connection.moveShapeHub.server.calculate(left, top);
                    }
                });
            });
            $.connection.moveShapeHub.client.updateshape = function (left, top) {
                $("#yourshape").offset({ "left": left, "top": top });
            };
        });
    </script>
    <div id="myshape"></div>
    <div id="yourshape"></div>
    <div id="indicator"></div>
</body>
</html>

查看关于使用append方法的jquery文档。这听起来就是你所需要的。http://api.jquery.com/append/