我有一个登录页面,我添加了一个验证,每当输入为空时你无法登录,我希望验证消息在用户输入一些输入时消失。我希望很清楚。这是我的代码:
function Validation() {
var x = document.getElementById("username").value;
var y = document.getElementById("password").value;
if (x == "") {
document.getElementById("demo1").innerHTML = "*please write name";
} else {
document.getElementById("demo1").innerHTML = "";
}
if (y == "") {
document.getElementById("demo2").innerHTML = "*please write password";
return false;
} else {
document.getElementById("demo2").innerHTML = "";
}
}

<div id="form-wrapper">
<label for="username">UserName </label>
<input type="text" id="username" name="myuser" /><span class="validation" id="demo1"> </span>
<br/> <br/>
<label for="password"> Password </label>
<input type="password" id="password" name="mypassword" />
<span class="validation" id="demo2"> </span>
<br />
<input type="submit" id="login" value="Log in" onclick="return Validation()" /> <br />
<input type="checkbox" checked="checked" /> Remember me
</div>
&#13;
答案 0 :(得分:2)
用户开始输入密码或用户名框后,您需要立即调用wss://subscriptions.ap-northeast-1.graph.cool/v1/###
功能。你可以通过Validation()
事件来实现它,比如
onkeyup
<input type="password" id="password" name="mypassword" onkeyup="Validation()" />
function Validation() {
var x = document.getElementById("username").value;
var y = document.getElementById("password").value;
if (x == "") {
document.getElementById("demo1").innerHTML = "*please write name";
} else {
document.getElementById("demo1").innerHTML = "";
}
if (y == "") {
document.getElementById("demo2").innerHTML = "*please write password";
return false;
} else {
document.getElementById("demo2").innerHTML = "";
}
}