Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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 HTML表单验证问题 功能检查(n、邮件、消息) { if(name.toLowerCase()=“”) { 警告(“请输入您的姓名”); document.getElementById(“名称”).select(); document.getElementById(“Name”).focus(); 返回false; } else if(lname.toLowerCase()==“”) { 提醒(“请输入您的电子邮件”) document.getElementById(“email”).select(); document.getElementById(“email”).focus(); 返回false; } 否则如果(ph==“”) { 警报(“请输入您的联系电话。”) document.getElementById(“message”).focus(); 返回false; } 返回true; }_Javascript_Html_Validation - Fatal编程技术网

Javascript HTML表单验证问题 功能检查(n、邮件、消息) { if(name.toLowerCase()=“”) { 警告(“请输入您的姓名”); document.getElementById(“名称”).select(); document.getElementById(“Name”).focus(); 返回false; } else if(lname.toLowerCase()==“”) { 提醒(“请输入您的电子邮件”) document.getElementById(“email”).select(); document.getElementById(“email”).focus(); 返回false; } 否则如果(ph==“”) { 警报(“请输入您的联系电话。”) document.getElementById(“message”).focus(); 返回false; } 返回true; }

Javascript HTML表单验证问题 功能检查(n、邮件、消息) { if(name.toLowerCase()=“”) { 警告(“请输入您的姓名”); document.getElementById(“名称”).select(); document.getElementById(“Name”).focus(); 返回false; } else if(lname.toLowerCase()==“”) { 提醒(“请输入您的电子邮件”) document.getElementById(“email”).select(); document.getElementById(“email”).focus(); 返回false; } 否则如果(ph==“”) { 警报(“请输入您的联系电话。”) document.getElementById(“message”).focus(); 返回false; } 返回true; },javascript,html,validation,Javascript,Html,Validation,========================================================= <script type="text/javascript"> function check(n,mail,msg) { if(name.toLowerCase()== "") { alert("Please Enter your name."); document.getElementById("Name").select(); document.getEle

=========================================================

<script type="text/javascript">
function check(n,mail,msg)
{
if(name.toLowerCase()== "")
{
alert("Please Enter your name.");
document.getElementById("Name").select();
    document.getElementById("Name").focus();
    return false;
}
else if(lname.toLowerCase()== "")
{
    alert("Please Enter your email.")
    document.getElementById("email").select();
    document.getElementById("email").focus();   
    return false;
}
else if(ph == "")
{ 
    alert("Please Enter your Contact Number.")
    document.getElementById("message").focus();
    return false;
}

return true;
}
<form method="post" name="contact_form" action="contact-form-handler.php">

<p> Your Name:
<input type="text" name="name"></p>

<p>Email Address:
<input type="text" name="email"></p>

<p>Message:
<textarea name="message"></textarea></p>

您的姓名:

电邮地址:

信息:

=========================================================

<script type="text/javascript">
function check(n,mail,msg)
{
if(name.toLowerCase()== "")
{
alert("Please Enter your name.");
document.getElementById("Name").select();
    document.getElementById("Name").focus();
    return false;
}
else if(lname.toLowerCase()== "")
{
    alert("Please Enter your email.")
    document.getElementById("email").select();
    document.getElementById("email").focus();   
    return false;
}
else if(ph == "")
{ 
    alert("Please Enter your Contact Number.")
    document.getElementById("message").focus();
    return false;
}

return true;
}
<form method="post" name="contact_form" action="contact-form-handler.php">

<p> Your Name:
<input type="text" name="name"></p>

<p>Email Address:
<input type="text" name="email"></p>

<p>Message:
<textarea name="message"></textarea></p>

=========================================================

<script type="text/javascript">
function check(n,mail,msg)
{
if(name.toLowerCase()== "")
{
alert("Please Enter your name.");
document.getElementById("Name").select();
    document.getElementById("Name").focus();
    return false;
}
else if(lname.toLowerCase()== "")
{
    alert("Please Enter your email.")
    document.getElementById("email").select();
    document.getElementById("email").focus();   
    return false;
}
else if(ph == "")
{ 
    alert("Please Enter your Contact Number.")
    document.getElementById("message").focus();
    return false;
}

return true;
}
<form method="post" name="contact_form" action="contact-form-handler.php">

<p> Your Name:
<input type="text" name="name"></p>

<p>Email Address:
<input type="text" name="email"></p>

<p>Message:
<textarea name="message"></textarea></p>

我在HTML验证方面遇到问题,因为当我单击按钮时,没有执行任何验证。

请尝试以下按钮:

<input type="button" value="submit" onclick="return check(document.getElementById('name').value,document.getElementById('email').value,document.getElementById('message').value)" /> 

取而代之。。在表单上添加验证,如下所示:

<input type="button" value="submit" onclick="function(){ check(document.getElementById('name').value,document.getElementById('email').value,document.getElementById('message').value)}" /> 

这可以100%工作


<form method="post" name="contact_form" action="contact-form-handler.php" 
onsubmit="return validateForm()">
您的姓名:

电邮地址:

信息:

使用此html标记。它有你错过的ID。
您正在使用document.getElementById(“名称”)。但是输入字段没有id“name”。其他字段也一样

我不太确定,因为我没有写过类似的东西。但我不应该只是
。没有
return`word?另外,我认为
click()
函数不需要任何参数,因为您可以在函数中请求这些参数。表单中没有id
email
message
name
的元素……输入和文本区域中没有id。但您正在尝试查询document.getElementById(“名称”)。没有
lname
name
ph