-1

所以我有一个用 php 和 jquery 构建的聊天室网站,但它使用 2 个不同版本的 jquery 并且我添加的一些新页面相互冲突(即使我在其他页面上同时链接了两个 jquery 版本) 所以我需要帮助转换代码,因为我不知道什么是折旧的,什么不是我的 jquery 1.3 代码

    // jQuery Document
    $(document).ready(function() {
        //If user submits the form
        $("#submitmsg").click(function() {
            var clientmsg = $("#usermsg").val();
            $.post("/chatPost/defaultchatpost.php", {
                text: clientmsg
            });
            $("#usermsg").attr("value", "");
            return false;
        });
        //Load the file containing the chat log
        function loadLog() {
            var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
            $.ajax({
                url: "/chatLogs/defaultchatlog.html",
                cache: false,
                success: function(html) {
                    $("#chatbox").html(html); //Insert chat log into the #chatbox  div
                    var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
                    if (newscrollHeight > oldscrollHeight) {
                        $("#chatbox").animate({
                            scrollTop: newscrollHeight
                        }, 'normal'); //Autoscroll to bottom of div
                    }
                },
            });
        }
        setInterval(loadLog, 500); //Reload file every 2.5 seconds
        //If user wants to end session
        $("#exit").click(function() {
            var exit = confirm("Are you sure you want to end the session?");
            if (exit == true) {
                window.location = 'defaultchat.php?logout=true';
            }
        });
    });

有人可以帮我吗,我已经尝试了很长时间,我将不胜感激

4

1 回答 1

0

您似乎尝试使用 ajax html 从主界面调用 /chatLogs/defaultchatlog.html。在这种情况下,您不必在 defaultchatlog.html 中添加 jquery,即使在其他称为 html 文件的 ajax 中也是如此。所有功能都必须在主 UI 中,而不是在通过 ajax html 调用的部分 html 文件中。例如:main.html 和 defaultchatlog.html ......我希望这会有所帮助

main.html

<html>
    <head>
        <scrpt src="jquery.js"></script>
    </head>
    <body>
        <div id="chatWindows"></div>
    </body>
    <script>
        $(document).ready(function(){
            $.ajax({
            url: "chatlog.html",
            cache: false,
            success: function(html) {
                $("#chatWindows").html(html); //Insert chat log into the #chatbox  div
            },
        });
        });
        function clearLogs(){
            $("#logs").empty();
        }
    </script>
</html>

chatlog.html

<div>
    <ul id="logs">
        <li>Hi</li>
    </ul>
    <button onclick="clearLogs();">Clear</button>
</div>
于 2016-10-21T00:31:26.990 回答