Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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 - Fatal编程技术网

如果和其他状态不工作(javascript)(html)

如果和其他状态不工作(javascript)(html),javascript,html,Javascript,Html,Javascript位: function emptyF(){ var x = document.getElementById("get"); if(x.value.match("")){ alert("missing fields"); return false; } else{ return true; } } html位: &l

Javascript位:

 function emptyF(){
        var x = document.getElementById("get");
        if(x.value.match("")){
            alert("missing fields");
            return false;
        }
        else{
            return true;
        }
    }
html位:

<h1>Login</h1>
<form action="home.php" method="post">
Username: <input type="text" id="get" onkeyup="myFunction()" name="username" value="<?php echo $_COOKIE['name'];?>" /><br /><br />
<input type="submit" onclick="emptyF()" name="submit"  value="Log In" />
登录

用户名:如果要将值与空字符串进行比较,只需直接进行比较:

if (x.value === "")

.match()
函数将其参数强制转换为正则表达式,并且每个字符串都将匹配空字符串。

仅使用
返回文档。getElementById('get')。value.trim()!=''
x.value.match(“”
可能应该是
x.value==”
@CodeNewbie
onclick
应该是
onclick=“return emptyF()”
不管它在盯着代码看了几分钟后决定工作。我会记住回报,但现在一切都好。谢谢