如果和其他状态不工作(javascript)(html)
Javascript位:如果和其他状态不工作(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
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==”
@CodeNewbieonclick
应该是onclick=“return emptyF()”
不管它在盯着代码看了几分钟后决定工作。我会记住回报,但现在一切都好。谢谢