zoukankan      html  css  js  c++  java
  • Online_ChatRomm

     $(document).ready(function() {
            var timeid = null;
            timeid = setInterval('counter()', 5000);
        }).keydown(function(event) {
        var key = window.event ? event.keyCode : event.which;
        if ((key.toString() == "13") && (event.ctrlKey)) {
            sendMsg();
        }
        });
        function counter() {
            $.ajax({
                url: "BaseAjaxAppliction/newmsg.ashx",
                type: "get",
                dataType: "html",
                data: "myId=<%= MyId %>&friendId=<%= FriendId %>",
                success: function(msg) {
                    if (msg != "0") {
                        $("#body").append(msg);
                    }
                }
            });
            setTimeout('scrollDiv()', 100);
        }
        function sendMsg() {
            if ($("#content").val() == "") {
                $("#error").html("<span style=\"font-color:red;\">发送消息不能为空!</span>");
                return false;
            }
            $.get("BaseAjaxAppliction/newmsg.ashx", { body: $("#content").val(), myId: "<%= MyId %>", friendId: "<%= FriendId %>" },
                    function(msg) {
                        if (msg == "1") {
                            var de = new Date();
                            $("#body").append("<ul><li>我  " + de.toLocaleString() + "</li><li>说:" + $("#content").val() + "</li></ul>");
                            $("#content").val("");
                        }
                        else {
                            $("#error").html("<span style=\"color:red;\">消息发送失败,请重发!</span>");
                            $("#content").val("");
                        }
                    });
                    setTimeout('scrollDiv()', 100);
        }
        function scrollDiv(){
            $("#bodys").scrollTop($("#body").height());
        }
  • 相关阅读:
    转载.net泛型理解说明
    转载Repository 和Unit of work的使用说明
    libtool的工作原理
    带有通配符的字符串匹配算法-C/C++
    linux core文件机制
    grep多条件和sed合并两行
    BZOJ 3232 圈地游戏 (分数规划 + SPFA找负/正环)
    CSP2019 D1T3 树上的数 (贪心+并查集)
    CSP-S 2019 第二轮 退役记
    object-c中的int NSInteger NSUInteger NSNumber辨析
  • 原文地址:https://www.cnblogs.com/Andon_liu/p/1340642.html
Copyright © 2011-2022 走看看