Javascript登录重定向不工作

Javascript登录重定向不工作,javascript,button,if-statement,login,document.write,Javascript,Button,If Statement,Login,Document.write,所以,在我的网页设计课上,我的老师让我教这个课简单的javascript,我想制作一个简单的网站,我和我的老师都可以使用它。我希望它是一个有登录框的东西(我认为很简单),当你登录时,如果你使用我的登录或我老师的登录,它会工作,它会创建按钮或重定向到另一个有按钮的页面,但出于某种原因,我在登录时使用if-else语句(因为只有两种情况是正确的,所以我不想工作 编辑:我仍在学习Javascript,对它的理解只足以教授它的一些非常基本的部分。(这就是我需要学习的全部内容)我所要做的就是让按钮出现,这

所以,在我的网页设计课上,我的老师让我教这个课简单的javascript,我想制作一个简单的网站,我和我的老师都可以使用它。我希望它是一个有登录框的东西(我认为很简单),当你登录时,如果你使用我的登录或我老师的登录,它会工作,它会创建按钮或重定向到另一个有按钮的页面,但出于某种原因,我在登录时使用if-else语句(因为只有两种情况是正确的,所以我不想工作

编辑:我仍在学习Javascript,对它的理解只足以教授它的一些非常基本的部分。(这就是我需要学习的全部内容)我所要做的就是让按钮出现,这样我就可以使用它们来调用创建信息的函数,这些信息在单击时会被写出来。例如,要在给出正确的登录信息时创建按钮,然后当出现的按钮出现时,您可以单击第一个按钮和a段此时将显示脚本标记

密码和姓名检查功能的工作没有太大问题,当我发出两个警报时,第一个警报是eeyup(如果正确),第二个警报是nnope(如果给出的信息错误),这两个功能都工作。只有在我尝试使用document.write时,我才会遇到问题

*目前,它所做的是按钮在屏幕上闪烁一秒钟,然后消失,登录框/屏幕再次出现。*

我使用的登录功能是:

        <script type="text/javascript">
function validator(){
    var name = document.KageForm.User.value;
    var password= document.KageForm.pass.value;
    if(password=="mypassword" && name=="myusername"|| password=="myteacherspassword" &&name=="myteachersname" ){
  document.write(showbuttons());
} else {
    document.write("This is not meant for you to see.");
}}
</script>

函数验证器(){
var name=document.KageForm.User.value;
var password=document.KageForm.pass.value;
如果(密码==“mypassword”&&name==“myusername”| |密码==“myteacherspassword”&&name==“myteachersname”){
document.write(showbuttons());
}否则{
写下(“这不是给你看的。”);
}}
显示按钮的函数showbuttons如下所示:

function showbuttons(){
    document.write("<div><form><input type=\"button\" value=\"Starting Your Script\" onclick=\"FirstThingsFirst()\"/><br/><input type=\"button\" value=\"Learn about document.write\" onclick=\"writing()\" /><br/><input  type=\"button\" value=\"Variables\"onclick=\"settingVariables()\" /><br/><input type=\"button\" value=\"Using Functions\" onclick=\"usingFunctions()\" /><br/><input type=\"button\" value=\"If Statements\" onclick=\"usingIfStatements()\" /><br/><input type=\"button\" value=\"Else Statements\" onclick=\"usingElseStatements()\" /><br/><input type=\"button\" value=\"Return to Login\" onclick=\"homepage()\" /></form></div>")
    document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}
函数showbuttons(){
文档。写(“







”) document.body.style.backgroundImage=“url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')"; document.getElementById('thisshouldbeewhite').style.color=“white”; document.getElementById('thisshouldbeewhite').style.width=“400px”; document.getElementById('ThisShouldbebeWhite').style.fontFamily=“helvetica”; }
整个页面的总代码如下:(如果按钮弹出的文本有任何不准确之处,请指出)


正文{背景图像:url(https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg)}
身体{
字体系列:helvetica;
颜色:深色;
}
h2{color:darkviolet;}
#tag1{宽度:480px;}
#包装{宽度:960px;边距:0自动;}
}
div{
保证金:5px;
边框:5px实心暗色;
宽度:50%;
}
img{
宽度:20.00%;
身高:20.00%;
}
ullia{
利润率:10px;
填充:2px;
背景#f2a7c6;
浮动:左;
边界:2px;
}
a:链接{文本装饰:无
颜色:darkviolet;}
h3{
字体系列:helvetica;
颜色:深色
}
#白色的{
颜色:白色;
}
/*

*/ 函数FirstThingsFirst(){ var mytext=“要开始将Javascript写入页面,必须首先使用脚本标记。标记为'script'类型=\”text/Javascript\“结束标记仅为/script。您可以在页面标题、样式标记之后或身体的任何位置使用Javascript。就我个人而言,我更喜欢将所有脚本或至少我的函数放在页面的头部。” 文件。编写(mytext); document.body.style.backgroundImage=“url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')"; document.getElementById('thisshouldbeewhite').style.color=“white”; document.getElementById('thisshouldbeewhite').style.width=“400px”; document.getElementById('ThisShouldbebeWhite').style.fontFamily=“helvetica”; } 函数编写() { var mytext=“若要在屏幕上写出一些内容,请使用命令‘document.write()’。若要获得想要显示的内容,请在副题中在其周围加上量化标记。若要写出‘bacon’,请在脚本中加上:document.write(‘bacon’)。document.write()用于许多事情,主要显示基于用户提供给页面的输入数据的信息,这些数据适合页面创建者定义的变量。例如,document.write(variableX())将打印为variableX输入的任何内容。” 文件。编写(mytext); document.body.style.backgroundImage=“url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')"; document.getElementById('thisshouldbeewhite').style.color=“white”; document.getElementById('thisshouldbeewhite').style.width=“400px”; document.getElementById('ThisShouldbebeWhite').style.fontFamily=“helvetica”; } 函数设置变量(){ document.write(“要创建一个变量,输入'var\'后跟一个空格,然后输入变量的名称,an=然后输入变量的值。因此,如果你心里有食物,想让变量成为'bacon\,那么你的变量应该是:var food=\'bacon\”) document.body.style.backgroundImage=“url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')"; document.getElementById('thisshouldbeewhite').style.color=“white”; document.getElementById('thisshouldbeewhite').style.width=“400px”; document.getElementById('这应该是wh
    <!doctype html>
    <html>

    <head>

            <style type="text/css"> 

      body {background-image:url(https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg)}
body{
    font-family:helvetica;
    color:darkviolet;
}
    h2 {color:darkviolet;}
    #tag1 {width:480px;}
#wrapper { width:960px;margin:0 auto; }
}

    div {
    margin: 5px;
      border: 5px solid darkviolet;
width:50%;

}
  img {
    width:20.00%;
    height:20.00%;

   }
ul li a {
    margin: 10px;
    padding: 2px;
    background: #f2a7c6;
    float: left;
    border: 2px ;
}

a:link {text-decoration:none
    color:darkviolet;}
    h3 {
        font-family:helvetica;
    color:darkviolet
    }
   #white {
    color:white;
   }
    </style>
    <script type="text/javascript">


/*<input type=\"button\" value=\"Starting Your Script\" onclick=\"FirstThingsFirst()\"/><br/><input type=\"button\" value=\"Learn about document.write\" onclick=\"writing()\" /><br/><input  type=\"button\" value=\"variables\"onclick=\"settingVariables()\" /><br/>input type=\"button\" value=\"Using Functions\" onclick=\"usingFunctions()\" /><br/>input type=\"button\" value=\"If Statements\" onclick=\"usingIfStatements()\" /><br/>input type=\"button\" value=\"Else Statements\" onclick=\"usingElseStatements()\" />*/

function FirstThingsFirst() {
var mytext = "<div id=\"thisshouldbewhite\"> To start writing Javascript into your page, you must first make use of the script tag. The tag is 'script' type=\"text/javascript\"  with the closing tag simply being /script. you can use a Javascript either in your heading of your page, after the style tag, or anywhere in your body. Personally, I prefer to put all my script, or at least my functions,  in the head of my page.</div> <input type=\"button\" value=\"Return to Home\" onclick=\"homepage()\" />"
    document.write(mytext);
document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}


function writing() 
{    
var mytext = "<div id=\"thisshouldbewhite\">To write something out on your screen, you use the command \'document.write()'. To get what you want to appear, put qutation marks around it in the paranthesis. So to write out \"bacon\", you would put: document.write(\"bacon\") in your script. Document.write() is used for many things, mainly displaying information based on input data given to the page by the user that fits into variables defined by the creator of the page. For example, document.write(variableX()) would print out anything that has been put in for variableX.</div><input type=\"button\" value=\"Return to Home\" onclick=\"homepage()\" />"
    document.write(mytext);
document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";

}
function settingVariables(){
    document.write("<div id=\"thisshouldbewhite\">to create a variable, youtype in \'var\' followed by a space, then the name of the variable, an = then what the variable is equal to. So, if you had food on your mind and wanted your variable to be \'bacon\' your variable would be: var food=\"bacon\"</div><input type=\"button\" value=\"Return to Home\" onclick=\"homepage()\" />")
    document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}

function usingFunctions(){
  document.write("<div id=\"thisshouldbewhite\">Functions are used to use commands only when triggered, or to do multiple things at once. for example, open up a website and type in the following code: <br/> <i>function troll(){<br/>document.write(\"gotcha!\");<br/>document.write(gotcha());<br/> function gotcha(){<br/>document.write(\" hahahaha!\");<br/>document.write(troll())</i>;<br/> What this will do is that the first function will call the second function, and then when the second function is called it will call the first function.Since neither are being called at the moment, create a button in your html as usual, but in the starting tag, add the property\"onClick\". Name your button something like, 'start trolling' or something like that. So, your code for your input should look something like <i><-input type=\"button\" value=\"Starting Your Script\" onclick=\"FirstThingsFirst()\"/></i> <br/> obviously minus the dash at the start of the tag.</br><input type=\"button\" value=\"Commence Trolling\" onclick=\"troll()\"/></div><input type=\"button\" value=\"Return to Home\" onclick=\"homepage()\" />");
  document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}
function usingIfStatements(){
  document.write("<div id=\"thisshouldbewhite\">If statements are used to create scenarios such as login screens, since that is the use that will be most familiar to most of us. An If statement goes inside the function tag, so when in use the statement looks like this:<br/>function login(){<br/>if(conditions for if statement){commands for if statement to follow}}<br/> Here is an example of a functional function using an IF Statement:<br/>function login(){<br/>var name=\"your name\";<br/>if(name==\"your name\"){document.write(\"You are indeed yourself\")}}<br/>This would print out the words in the command following the If statement, since the statement is true, since the variable, \"name\" is equal to \"your name\"</div><input type=\"button\" value=\"Return to Home\" onclick=\"homepage()\" />");
  document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}

function usingElseStatements(){
    document.write("<div id=\"thisshouldbewhite\">So, we know how to make an If statement, now we are going to use Else statements. This would be like on a login screen, if you type in inaccurate information and it gives you an error message<i><br/>function login(){<br/>if(conditions for if statement){commands for if statement to follow}else(commands for script to follow if your If statement is not true)}</i><br/> Here is an example of a functional function using an IF Statement:<i><br/>function login(){<br/>var name=\"your name\";<br/>if(name==\"your name\"){document.write(\"You are indeed yourself\")else{document.write(\"you are not yourself when you're hungry.\")}}}<br/></i></div>")
    document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}


function troll(){
document.write("gotcha!");
document.write(gotcha());
}
function gotcha(){
document.write(" hahahaha!");
document.write(troll())
}

function homepage() 
{
    window.location.href = "file:///C:/Users/Admin/Documents/Websites/TEst.html";
}
function gotoButtons() 
{
    window.location.href = "file:///C:/Users/Admin/Documents/Websites/Buttons.html";
}


function showbuttons(){
    document.write("<div><form><input type=\"button\" value=\"Starting Your Script\" onclick=\"FirstThingsFirst()\"/><br/><input type=\"button\" value=\"Learn about document.write\" onclick=\"writing()\" /><br/><input  type=\"button\" value=\"Variables\"onclick=\"settingVariables()\" /><br/><input type=\"button\" value=\"Using Functions\" onclick=\"usingFunctions()\" /><br/><input type=\"button\" value=\"If Statements\" onclick=\"usingIfStatements()\" /><br/><input type=\"button\" value=\"Else Statements\" onclick=\"usingElseStatements()\" /><br/><input type=\"button\" value=\"Return to Login\" onclick=\"homepage()\" /></form></div>")
    document.body.style.backgroundImage="url('https://fc04.deviantart.net/fs70/f/2013/029/6/8/smoke_by_kage_kaldaka-d5t50d9.jpg')";
document.getElementById('thisshouldbewhite').style.color="white";
document.getElementById('thisshouldbewhite').style.width="400px";
document.getElementById('thisshouldbewhite').style.fontFamily="helvetica";
}
        </script>

        </head>
        <body>
           <script type="text/javascript">
      function validator(){
        var name = document.KageForm.User.value;
        var password= document.KageForm.pass.value;
        if(password=="mypassword" && name=="myusername"|| password=="myteacherspassword" &&name=="myteachersname" ){
      document.write(showbuttons());
    } else {
        document.write("This is not meant for you to see.");
    }}
        </script>
        <form name="KageForm">
            Username:<input type="text" name="User">
        <br/>
            Password: <input type="password" name="pass">
        <br/>
        <input type="image" src="https://a.deviantart.net/avatars/k/a/kage-kaldaka.png?6" 
         value="Submit" onclick="validator()" />
        <br/>
        <input type="button" value="Starting Your Script" onclick="FirstThingsFirst()"/>
        <br/>
        <input type="button" value="Learn about document.write" onclick="writing()" />
        <br/>
        <input  type="button" value="Variables" 
       onclick="settingVariables()" />
         <br/>
       <input type="button" value="Using Functions" onclick="usingFunctions()" />
       <br/>
       <input type="button" value="If Statements" onclick="usingIfStatements()" />
       <br/>
       <input type="button" value="Else Statements" onclick="usingElseStatements()" />
       <br/>
       <input type="button" value="" onclick="" />
       <br/>
       <input type="button" value="" onclick="()" />
       <br/>
       <input type="button" value="" onclick="()" />
       <br/>
       <input type="button" value="" onclick="()" />


        </form>



    </body>



    </html>
  (((password =="mypassword") && (name=="myusername")) || ((password=="myteacherspassword") && (name=="myteachersname")) )