用于表单验证的Bootstrap工具提示 [英] Bootstrap tooltip for form validation
本文介绍了用于表单验证的Bootstrap工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是相当不熟悉引导程序的人,似乎无法正确解决这个问题.我在表单验证中使用工具提示javascript功能,当输入字段中出现验证错误时会弹出该提示,我希望在输入字段onBlur中出现验证检查错误时出现工具提示,并在焦点上消失
I am fairly new to bootstrap and cant seem to get this right. I am using tooltip javascript functionality, on form validation, which popsup when there is validation errors in the input field, i want tooltip to appear when ever there is validation check errors in the input field onBlur and disappear on focus
我的HTML是:
<input class="span2" id="formName" rel="tooltip" data-placement="top" type="text" placeHolder="" onBlur="return validateName();" >
我的JavaScript是
my javascript is
function validateName()
{
var x=document.getElementById("formName").value;
if (x==null || x==""){
$('#formName').tooltip({ 'title': 'Name Must Not Be Empty!' });
} else { $('#formName').tooltip('hide') }
}
目前,它遵循的是鼠标悬停时出现的默认行为,我希望在光标离开输入字段时使其出现
Currently it is following default behaviour of appearing on mouseover, i want to make it appear whenever cursor leaves the input filed
推荐答案
将事件触发器更改为 onkeyup
:
<input class="span2" id="formName" rel="tooltip" data-placement="top" type="text" placeHolder="" onkeyup="return validateName();" >
这篇关于用于表单验证的Bootstrap工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文