好的,所以这听起来可能是一个非常愚蠢的问题,但我是 Javascript 的新手。
基本上,我希望我的页面只在用户未填写的文本框旁边写下“请填写”字样。
<!DOCTYPE html>
<head>
<title>Easy Budget</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<script>
function myFormFunction()
{
if (document.myForm.Name.value == "")
{
alert("Name must be filled in");
document.myForm.Name.focus();
return false;
}
if (document.myForm.Surname.value == "")
{
alert("Surname must be filled in");
document.myForm.Surname.focus();
return false;
}
if (document.myForm.Income.value == "")
{
alert("Income must be filled in");
document.myForm.Income.focus();
return false;
}
return (true) ;
}
</script>
</head>
<header>
</header>
<body>
<form name="myForm" onSubmit="return myFormFunction()" method="post">
<h3>Work Out Your Budget</h3>
<p><h4>Personal Details:</h4></p>
<p> Name: <input type="text" name="Name"></p>
<p> Surname: <input type="text" name="Surname"></p>
<p> Income: <input type="text" name="Income"></p>
<p><h4>What are your monthly expenses?</h4></p>
<p><input type="checkbox" name="Groceries">Groceries</input></p>
<p><input type="checkbox" name="Car">Car</input></p>
<p><input type="checkbox" name="PublicTransport">Public Transport</input></p>
<p><input type="checkbox" name="Rent">Rent</input></p>
<p><input type="checkbox" name="Pets">Pets</input></p>
<p><input type="checkbox" name="Drinking">Drinking</input></p>
<p><input type="checkbox" name="Smoking">Smoking</input></p>
<p><input type="checkbox" name="NightsOut">Night's Out</input></p>
<p><button type="Submit" value="Submit">Submit</Button></p>
</form>
</body>
</html>
这是整个文档,正如我所说的,它工作正常,但我不希望每次都弹出警报。我只是希望它显示在文本框“请填写”旁边
提前致谢