Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不是';它不是在检查正确的值吗?(Javascript/HTML)_Javascript_Html_Forms_Validation - Fatal编程技术网

为什么不是';它不是在检查正确的值吗?(Javascript/HTML)

为什么不是';它不是在检查正确的值吗?(Javascript/HTML),javascript,html,forms,validation,Javascript,Html,Forms,Validation,这是我的密码: <html> <body> <script type="text/javascript"> function CheckPwd() { if(document.forms['frm'].pass.value == "magicisreal") { alert('Welcome, ADMIN...'); return true; } return false; } </script>

这是我的密码:

<html>
<body>
<script type="text/javascript">
function CheckPwd()
{
 if(document.forms['frm'].pass.value == "magicisreal")
    {
      alert('Welcome, ADMIN...');
      return true;
    }
      return false;
}
</script>

Password:
<br>
<input type="password" name="pass">
<br><br>
<input type="submit" value="Continue" onclick="return CheckPwd()">

</body>
</html>

函数CheckPwd()
{
if(document.forms['frm'].pass.value==“magicisreal”)
{
警报(“欢迎,管理员…”);
返回true;
}
返回false;
}
密码:




当在文本框中输入值“magicisreal”时,它应该会返回警报。确切地说,我做错了什么并没有导致这个结果?

您缺少表单。试试这个-


函数CheckPwd(){
if(document.forms['frm'].pass.value==“magicisreal”){
警报(“欢迎,管理员…”);
返回true;
}
返回false;
}
密码:




您使用的是
document.forms
,它要求HTML中存在
表单
,但您尚未定义它。 只需使用
name=frm
定义HTML表单即可

函数CheckPwd(){
if(document.forms[“frm”].pass.value==“magicisreal”){
警报(“欢迎,管理员…”);
返回true;
}
返回false;
}

密码:




首先,没有名为frm的表单。 因此,您正在检查的if语句无效。 使用以下代码段来实现您要查找的内容:


函数CheckPwd()
{
var password=document.getElementById('pass-input')。值;
console.log(密码);
如果(密码==“magicisreal”)
{
警报(“欢迎,管理员…”);
返回true;
}
返回false;
}
密码: