引导工具提示手动触发不工作
Bootstrap Tooltip manual trigger not working
我在这里面临着一个严重的困境,我在输入标签上使用了bootstrap工具提示来进行表单验证,即当有表单验证错误时,工具提示会自动出现在输入标签周围,问题是
1)工具提示只在第二次调用onBlur时出现或触发,尽管它应该在第一次光标离开输入标签时出现,代码为$("input#formName").each(function() {
$("#formName").on("blur",this, function(){
var x=document.getElementById("formName").value;
//
if (x==null || x=="")
{
var error = "Name Must Not Be Empty";
$('#formName').tooltip({
trigger: 'manual',
title: error
}).on({
blur: function() {
$(this).tooltip('show');
},
focus: function() {
$(this).tooltip('hide');
}
});
}else{
$('#formName').data('tooltip',false);
}
});
$("#formName").on("blur",this, function(){
var y=document.getElementById("formName").value;
if (y.length < 6){
var error2 = "Length of Name Must Br Greater than 6";
$('#formName').tooltip({
trigger: 'manual',
title: error2
}).on({
blur: function() {
$(this).tooltip('show');
},
focus: function() {
$(this).tooltip('hide');
}
});
}else{
$('#formName').data('tooltip',false);
}
})
});
2)我在这里有两个检查,上面的代码只工作一次,而不是每次当光标离开特定的输入标签时,如在代码中,即如果第二个条件被触发,之后我留下它为空,它应该触发第一个函数即"名称不得为空",而不是"长度不得大于6"
我会把你的重写改成这样:
$("input#formName").each(function() {
var $this = $(this);
$this.on("blur",this, function(){
var x = $this.val();
var error;
if (x==null || x=="") { error = "Name Must Not Be Empty"; }
elseif (x.length < 6) { error = "Length of Name Must Br Greater than 6"; }
$this.tooltip({
trigger: 'manual',
title: error
}).on({
blur: function() {
$(this).tooltip('show');
},
focus: function() {
$(this).tooltip('hide');
}
});
});
});
并将所有输入更改为使用class(.formName
)而不是id(#formName
)
相关文章:
- 谷歌散点图-{role:'style'}{role:#39;工具提示'}不能以JSON形式工作
- 关闭Body Click事件的工具提示-工作不正常
- 如何使工具提示从函数本身之外的元素工作
- 多行工具提示无法以编程方式工作
- 如果文本在高图表中较多,则工具提示无法正常工作
- 筛选器操作后,工具提示停止工作
- ExtJS 4.2.1 - 选项卡面板中的网格 - 工具提示停止工作
- 悬停和焦点上的响应式 jQuery 工具提示无法正常工作
- 只要单击页面上的任何内容,引导工具提示就会停止工作
- 如何使工具提示在 HTML 表单中工作
- 如何获取工具提示以在现有 JS 函数中工作
- 引导工具提示不't在与第一个数据表不同的页面中工作
- 类选择器不'不能在通过AJAX加载的工具提示内容中工作
- <br>不在工具提示的标题标记中工作
- 为什么这个工具提示没有'不在IE工作吗?错误:应为对象
- 引导工具提示与角不工作
- 启动工具提示在任何其他事件运行后停止工作
- Jquery工具提示不能在文本/模板上工作
- 工具提示器突然不工作了
- 工具提示不能在ie中工作