Javascript js模糊验证表
我正在尝试验证输入值,但使用此代码我没有收到消息(输入框仍变为红色):Javascript js模糊验证表,javascript,html,validation,Javascript,Html,Validation,我正在尝试验证输入值,但使用此代码我没有收到消息(输入框仍变为红色): document.forms.richiedipe.your email.addEventListener('blur',函数(e){ 如果(!e.target.validity.valid){ e、 target.setCustomValidity(“Heyy”); } }); 姓名 电子邮件 用Javascript获取表单的另一种方法是: document.forms['form_name'] document.
document.forms.richiedipe.your email.addEventListener('blur',函数(e){
如果(!e.target.validity.valid){
e、 target.setCustomValidity(“Heyy”);
}
});
姓名
电子邮件
用Javascript获取表单的另一种方法是:
document.forms['form_name']
document.forms['form_name']['form_element_name']
使用:
document.forms['richiediAPE']['your-email'].addEventListener('blur',function(e){
/* Yourself actions. */
alert(document.forms['richiediAPE']['your-email'].value);
/* This alerts the value of the text input. */
);
但您必须知道,在document.forms中,您可以通过名称(name tag,name=“”)获得一个表单和一个元素,是否确定?请发布一些html,以便我们可以查看表单的布局。当我单击提交按钮时,我会收到消息“填写此字段”。现在,使用.addEventListener,我获得了自定义有效性。但是当我更改焦点时,我也希望获得消息,而不必单击submit。你只需要将焦点事件添加到元素中,比如:
element.onfocus=function(){/*..*/}
我想知道是否有一个命令可以显示验证的工具提示,而不必单击submit按钮。嗯,我仍然没有得到你想要的工具提示是什么?或者您想在不单击“提交”按钮的情况下提交表单?当您提交表单且所需输入为空时,我会收到一条带有消息“请填写此字段”的工具提示。我可以在不单击提交的情况下获得此工具提示吗?
document.forms['richiediAPE']['your-email'].addEventListener('blur',function(e){
/* Yourself actions. */
alert(document.forms['richiediAPE']['your-email'].value);
/* This alerts the value of the text input. */
);