无法找到id ***的用法

时间:2015-03-26 17:15:10

标签: javascript jquery signalr

目前正在使用singalR,但我在visual studio中遇到以下错误:

Can't find usage of id 'displayname'
Can't find usage of id 'message'
Can't find usage of id 'sendmessage'

我不知道我做错了什么。这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <title>Chat</title>
    <style type="text/css">
        .container {
            background-color: #99CCFF;
            border: thick solid #808080;
            padding: 20px;
            margin: 20px;
        }
    </style>
</head>
<body>

<div class="container">
    <input type="text" id="message"/>
    <input type="button" id="sendmessage" value="Send"/>
    <input type="hidden" id="displayname"/>
    <ul id="discussion"></ul>
</div>
<script src="Scripts/jquery-2.1.3.js"></script>
<script src="Scripts/jquery.signalR-2.2.0.js"></script>
<script src="http://localhost:8080/signalr/hubs"></script>
<script type="text/javascript">

    $(function () {
        $.connection.hub.url = "http://localhost:8080/signalr";

        var chat = $.connection.myHub;

        chat.client.addMessage = function(name, message) {
            var encodedName = $("<div />").text(name).html();
            var encodedMsg = $("<div />").text(message).html();
            $("#discussion").append("<li><strong>" + encodedName
                + "</strong>:&nbsp;&nbsp;" + encodedMsg + "</li>");
        };
        $("#displayname").val(prompt("Enter your name:", ""));
        $("#message").focus();

        $.connection.hub.start().done(function() {
            $("#sendmessage").click(function() {
                chat.server.send($("#displayname").val(), $("#message").val());
                $("#message").val("").focus();
            });
        });
    });
</script>
</body>
</html>

0 个答案:

没有答案