用javascript / php创建聊天登录系统?

时间:2014-02-04 12:13:41

标签: javascript php html

$(function() {
    $('.newMessage').hide();
    $('#messageBoxSignIn').click(function() {
        $('#username').focus();
    });
}) ;


$(function() {
    $('.error').hide();
    $('#signIn').click(function() {
        var username = $('#username').val();

        if (username == "" || username == "Enter Username") {
            $('.error').show();
            return false;
        }


        $('#messageBoxSignInForm').hide();
        $('.newMessage').show();

        var dataString = 'username=' + username;

        $.ajax({
            type: "POST",
            url: "singinout.php",
            data: dataString, 
            success: function () {
                $('.user').html('<span>Welcome <span id="loggedUser">' + username + '</span>!</span> <a id="signOut" onclick="window.location.reload()">SIGN OUT</a>');
            }

            });

    });
})

我的javascript代码,我希望当用户在messageboxsignin中键入用户名时,“欢迎(用户名)!”将显示文本以及登录按钮将更改为退出。但它不起作用,文本没有出现,按钮仍然显示为登录。

HTML code:

<head>

<link rel="stylesheet" type="text/css" href="chatcss.css">

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>


<title>4thebored</title>

</head>

<body>

<div class="chatBox">
    <div class="user">
        <form name="signIn" action="" onsubmit="return false">
            <span class="error">Invalid Username</span>
            <input type="text" size="13px" name="username" id="username" value="Enter Username" onclick='document.signIn.username.value = ""' />
            <input type="submit" id="signIn" value="SIGN IN" />
            </form>
    </div>  

    <div class="main">
        <p>admin: *******</p>
    </div>


    <div class="messagebox">

    <form name="messageBoxSignInForm" id="messageBoxSignInForm" onsubmit="return false">
    <input type="submit" id="messageBoxSignIn" value="Sign in to enter chat" />
    </form>

    <form name="newMessage" class="newMessage" action="" onsubmit="return false">

    <div class="left">
    <textarea name="newMessageContent" id="newMessageContent">Enter your message here</textarea>
    </div>

    <div class="right">
    <input type="submit" id="newMessageSend" value="SEND" />
    </div>

    </form>

    </div>


</div>

<script src="signinout.js" type="text/javascript"></script>

</body>
</html>

0 个答案:

没有答案