当我点击提交按钮时,我编写了一个代码。文本只显示不到1秒钟,我该如何永久制作?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="#" method="post" onSubmit="return validcheck()">
<input type="text" id="firstname" name="firstname">
<input type="submit">
<div id="error1"></div>
</form>
<script>
function validcheck() {
var checkingg = document.getElementById('firstname').value;
if (checkingg == null || checkingg == "") {
document.getElementById('error1').innerHTML = 'please write something here';
} else {
document.getElementById('name-error').innerHTML = '';
}
}
</script>
</body>
</html>
&#13;
答案 0 :(得分:0)
从你的方法中返回false:
function validcheck() {
var checkingg = document.getElementById('firstname').value;
if (checkingg == null || checkingg == "") {
document.getElementById('error1').innerHTML = 'please write something here';
} else {
document.getElementById('name-error').innerHTML = '';
}
return false;
}
答案 1 :(得分:0)
您缺少退货声明
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="#" method="post" onSubmit="return validcheck()">
<input type="text" id="firstname" name="firstname">
<input type="submit">
<div id="error1"></div>
</form>
<script>
function validcheck() {
var checkingg = document.getElementById('firstname').value;
if (checkingg == null || checkingg == "") {
document.getElementById('error1').innerHTML = 'please write something here';
} else {
document.getElementById('name-error').innerHTML = '';
}
return false;
}
</script>
</body>
</html>
答案 2 :(得分:0)
您可以采取以下措施。
<form action="javascript:void(0)" method="post" onSubmit="return validcheck()">