2015-10-18 92 views
1

我试图验证输入的值,但使用此代码我没有得到这个消息(输入框变成仍为红色):JS模糊验证形式

+2

请张贴一些您的html,以便我们可以看到您的表单的布局。 –

回答

1

为了得到一个表格在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你得到一个FO rm和一个元素的名字(name tag,name =“”),当然?

+0

当我点击提交按钮时,我收到消息“填写此字段”。现在,使用.addEventListener,我可以获得我的CustomValidity。但我想要得到的消息也是当我改变焦点,而不必点击提交 –

+0

你只需要添加焦点事件的元素,如:'element.onfocus = function(){/ * .... * /}' – Hydro

+0

我在询问是否有命令显示验证工具提示,而不点击提交按钮。 –