简体   繁体   English

if-else for value javascript

[英]If-else for value javascript

now, I'm making a chatbox. 现在,我正在制作一个聊天室。 This is the code of the page were you can type in your name, but I will, when a user type my name (name of the webmaster) that the user got an error, because there aren't the webmaster. 这是你可以输入你的名字的页面代码,但是当用户输入我的名字(网站管理员的名字)时,我会用户输入错误,因为没有网站管理员。 My if-else function won't work. 我的if-else功能不起作用。 Is there anyone who can help me? 有没有人可以帮助我? Thanks 谢谢

<html>
    <head>
<title></title>
<style type="text/css">

    #main{
            width: 400px;
            height: 300px;
            background-color: #333;
            text-align: center;
            position: absolute;
            color: white;
            left:50%;
            margin-left: -200px;
            top: 50%;
            margin-top: -150px;
            }

        </style>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
        <script type="text/javascript">

        function show() {
        var text = document.getElementById('text');
        if (text.value == "Jonathan Cazaerck"){alert("Deze gebruiker mag u niet gebruiken");}
        else{
        $.post("processing.php", { stage: "newuser", username: $("#text").val()}, function(data){
        window.location = ("newsession.php?user="+data);}
        );}
  </script>
    </head>
    <body>
    <div id="main"><br><br><br><br>
    Geef je voor- en achternaam op: <br><br><input type="text" size="35" id="text"/><button id="send" onclick="show();">Verzenden</button>
    </div>
    </body>
</html>

你在show函数中错过了一个结束}

You need one more } at the end of your code. 代码末尾还需要一个}

    <script type="text/javascript">

    function show() {
    var text = document.getElementById('text');
    if (text.value == "Jonathan Cazaerck"){alert("Deze gebruiker mag u niet gebruiken");}
    else{
    $.post("processing.php", { stage: "newuser", username: $("#text").val()}, function(data){
    window.location = ("newsession.php?user="+data);}
    );}
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM