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());
        }
  • 相关阅读:
    考研系列一-线性表类(顺序存储)
    因特网协议分层及它们的服务模型
    矩阵归零
    字符编码(续)---Unicode与ANSI字符串转换以及分辨字符编码形式
    奇妙的位运算
    一道面试题Lintcode196-Find the Missing Number
    错误处理
    px 和 em 的区别
    简述同步和异步的区别
    简述一下 src 与 href 的区别
  • 原文地址:https://www.cnblogs.com/Andon_liu/p/1340642.html
Copyright © 2011-2022 走看看