简体   繁体   English

在 javascript 验证后,我无法加载我作为学生创建的另一个 html 页面。html

[英]I am not able to load another html page which I have created as student.html after javascript validation

Please tell me which function I can use to open student.html when the username and password is matching with the value I described in scrip tag.请告诉我当用户名和密码与我在脚本标签中描述的值匹配时,我可以使用哪个 function 打开 student.html。

<form>
    <input
        name="username"
        type="text"
        id="txt_username"
        class="text1"
        ondrop="return false;" 
        onpaste="return false;"
        style="color:#0000C0;border-style:Solid;font-family:verdana;font-size:Small;"
    />
    <input
        name="password"
        type="password"
        id="txt_password"
        class="text1"
        style="color:#0000C0;background-color:White;;border-style:Solid;font-family:verdana;font-size:Small;"
    />  
    <input
        type="submit"
        value="Login"
        onclick="validate()"
    />
</form>

<script type="text/javascript">
function validate() {
    var text1 = document.getElementById("txt_username");
    var text2 = document.getElementById("txt_password");
    if (text1.value == "root" && text2.value == "root") {
        alert("ok")
        load("student.html");
    } else {
        alert("fail");
        load("error.html");
    }
}
</script>

You can use window.location.replace("student.html") to replace the current document.您可以使用window.location.replace("student.html")替换当前文档。 Or you can use window.location.href = "student.html";或者你可以使用window.location.href = "student.html"; . .

 <form onsubmit="return validate(event)"> <input name="username" type="text" id="txt_username" class="text1" ondrop="return false;" onpaste="return false;" style="color:#0000C0;border-style:Solid;font-family:verdana;font-size:Small;" /> <input name="password" type="password" id="txt_password" class="text1" style="color:#0000C0;background-color:White;;border-style:Solid;font-family:verdana;font-size:Small;" /> <input type="submit" value="Login" /> </form> <script> function validate(event) { event.preventDefault(); var text1 = document.getElementById("txt_username"); var text2 = document.getElementById("txt_password"); if (text1.value == "root" && text2.value == "root") { window.location.replace("student.html"); } else { window.location.replace("error.html"); } } </script>

Use:利用:

 window.location.assign


 function validate() { var text1 = document.getElementById("txt_username"); var text2 = document.getElementById("txt_password"); if (text1.value == "root" && text2.value == "root") { window.location.assign("student.html"); } else { window.location.assign("error.html"); } }
 <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <form> <input name="username" type="text" id="txt_username" class="text1" ondrop="return false;" onpaste="return false;" style="color:#0000C0;border-style:Solid;font-family:verdana;font-size:Small;" /> <input name="password" type="password" id="txt_password" class="text1" style="color:#0000C0;background-color:White;;border-style:Solid;font-family:verdana;font-size:Small;" /> <input type="submit" value="Login" onclick="validate()" /> </form> </body> </html>

暂无
暂无

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

相关问题 我使用 javascript 在 HTML 中创建了一个表格 - I have created a table in HTML using javascript 网页加载后,包含HTML的HTML与onclick javascript不起作用 - Html include another Html with onclick javascript is not working after page load 更新html页面中的javascript并在更新后强制重新加载吗? - Update javascript in html page and force reload after I have updated it? 我无法使用 js node express 将数据传递到另一个 html 页面 - I am not able to pass data to another html page using js node express 我能够将文本数据加载到.js文件中的javascript数组中,但不能加载到html中 - I am able to load text data into a javascript array in .js file but not inside html 我正在使用javascript在另一个HTML页面中加载一些HTML页面。 它可以在Mozilla Firefox中正常工作,但不能在Google Chrome和IE10中工作 - I am using javascript to load some html page in another html page. Its working fine in Mozilla Firefox but not working in Google Chrome and IE10 使用 javascript 验证后无法重定向到另一个 html 页面 - Unable to redirect to another html page after validation using javascript 我使用html,css和Javascript创建的标签面板不起作用 - My tab panel which I created with html, css & Javascript is not working 检查电子邮件输入验证后,如何使用我的按钮将用户重定向到另一个HTML页面? - How do I redirect the user to another HTML page using my button after checking for email input validation? 我有一个使用ajax调用在另一个页面的div标签中加载的html页面,我想在加载的页面上触发javascript函数吗? - I have a html page that loaded in div tag in another page using ajax call I want to trigger javascript functions on loaded page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM