如何使用JS使用if语句将输入按钮重定向到另一个页面? [英] How Do I Make A input Button Redirect To Another Page with an if statement using JS?

查看:62
本文介绍了如何使用JS使用if语句将输入按钮重定向到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



这就是我所拥有的:

< form id =loginForm>





< label for =email>用户名< / label>

< input id =UserName type =textvalue =/>





< label for =password>密码< / label>

<输入id =密码类型=密码值=/>



< button id =logintype =button>登录< /按钮>

< script type =text / javascript>

if(document.getElementById(Password)。textContent =='moses')

document.getElementById(login)。onclick = function(){location.pathname =ITEHome.aspx};

< / script>





< / form>



我输入密码后,我需要按钮重定向到我的项目CiscoHome.aspx和ITEHome.aspx中的两个页面之一。 CiscoHome.aspx的密码是teag,ITEHome.aspx的密码是moses,如果没有输入,则应加载Login.aspx。我已经重定向工作但不是if语句。任何想法?

Hi All

this is what i have:
<form id="loginForm">


<label for="email">User Name</label>
<input id="UserName" type="text" value="" />


<label for="password">Password</label>
<input id="Password" type="password" value="" />

<button id="login" type="button">Login</button>
<script type="text/javascript">
if (document.getElementById("Password").textContent == 'moses')
document.getElementById("login").onclick = function () { location.pathname = "ITEHome.aspx" };
</script>


</form>

after i enter my password, i need the button to redirect to one of two pages in my project CiscoHome.aspx and ITEHome.aspx. the password for CiscoHome.aspx is "teag" and the password for ITEHome.aspx is "moses" and if non of those are entered, Login.aspx should be loaded. ive gotten the redirect to work but not the if statement. any ideas?

推荐答案

检查代码隐藏中的值(C#代码),然后使用 Response.Redirect [ ^ ]转到相应的页面。
Check the value in the codebehind (C# code) and then use Response.Redirect[^] to go to the appropriate page.


这篇关于如何使用JS使用if语句将输入按钮重定向到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆