Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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 希望在进行验证时显示文本而不是警报_Javascript_Jquery - Fatal编程技术网

Javascript 希望在进行验证时显示文本而不是警报

Javascript 希望在进行验证时显示文本而不是警报,javascript,jquery,Javascript,Jquery,好吧,这听起来可能是一个非常愚蠢的问题,但我对Javascript是全新的 基本上,我希望我的页面只在用户尚未填写的文本框旁边写上“请填写”字样 <!DOCTYPE html> <head> <title>Easy Budget</title> <link rel="stylesheet" type="text/css" href="stylesheet.css"/> <script> function myForm

好吧,这听起来可能是一个非常愚蠢的问题,但我对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>

轻松预算
函数myFormFunction()
{
如果(document.myForm.Name.value==“”)
{
警告(“必须填写姓名”);
document.myForm.Name.focus();
返回false;
}
如果(document.myForm.namname.value==“”)
{
警告(“必须填写姓氏”);
document.myForm.name.focus();
返回false;
}
如果(document.myForm.Income.value==“”)
{
警惕(“必须填写收入”);
document.myForm.Income.focus();
返回false;
}
返回(真);
}
制定你的预算
个人资料:

姓名:

姓:

收入:

你每月的费用是多少

杂货

汽车

公共交通

宠物

饮酒

吸烟

夜幕降临

提交

这是整个文档,正如我所说,它工作正常,但我不希望每次都弹出警报。 我只希望它显示在文本框“请填写”旁边


提前谢谢

好的,我现在好像已经收到了

这里是JS

<script>

function myFormFunction()

{
if (document.myForm.Name.value == "")
{
var el1 = document.getElementById("name");
el1.style.display = "block";
document.myForm.Name.focus();
return false;
}
if (document.myForm.Surname.value == "")
{
var el2 = document.getElementById("surname");
el2.style.display = "block";
document.myForm.Surname.focus();
return false;
}
if (document.myForm.Income.value == "")
{
var el3 = document.getElementById("income");
el3.style.display = "block";
document.myForm.Income.focus();
return false;
}
return (true) ;
}
</script>

函数myFormFunction()
{
如果(document.myForm.Name.value==“”)
{
var el1=document.getElementById(“名称”);
el1.style.display=“块”;
document.myForm.Name.focus();
返回false;
}
如果(document.myForm.namname.value==“”)
{
var el2=document.getElementById(“姓氏”);
el2.style.display=“块”;
document.myForm.name.focus();
返回false;
}
如果(document.myForm.Income.value==“”)
{
var el3=document.getElementById(“收入”);
el3.style.display=“块”;
document.myForm.Income.focus();
返回false;
}
返回(真);
}
这里是修改后的表格

<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">
<div id="name" style="display:none">Please enter your name</div></p>
<p> Surname:    <input type="text" name="Surname">
<div id="surname" style="display:none">Please enter your surname</div></p>
<p> Income:     <input type="text" name="Income">
<div id="income" style="display:none">Please enter your income</div></p>

 <br>

 <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>

制定你的预算
个人资料:

姓名: 请输入您的姓名

姓: 请输入您的姓氏

收入: 请输入您的收入


你每月的费用是多少

杂货

汽车

公共交通

宠物

饮酒

吸烟

夜幕降临

提交


您已经尝试了什么?$(document.myForm.Name)。在(“请填写”)之后;我没有得到帮助,反而被否决了。伟大的我确实说过这可能是一个愚蠢的问题,但我找不到任何东西雪人尝试了表演()和隐藏(),但似乎没有做到这一点,似乎应该有一些不太复杂的东西来做这么简单的事情