我正在使用 2 个引导日期选择器和 我想验证开始日期是否大于结束日期然后显示工具提示
这是我目前所拥有的:
$('#startdate_datepicker').tooltip({ content : "Example"});
警报出现了,但工具提示没有做任何事情,我不明白为什么。
有什么想法吗?
答案 0 :(得分:2)
刚刚检查了您的小提琴,您必须在多个地方进行更改。
您的代码将如下所示
这是你修改过的小提琴http://jsfiddle.net/b7urzdxj/
//title removed
<input class="form-control start_date" type="text" placeholder="Start Date" name="startdate_datepicker" id="startdate_datepicker" required="true">
//tooltip modified and programmatically triggered
if (start > end) {
e.preventDefault();
alert("Stop and tooltip");
$('#startdate_datepicker').tooltip({ title : "Example", placement:'bottom'});
$('#startdate_datepicker').tooltip('show')
}
答案 1 :(得分:1)
在您的 startdate_datepicker 元素上添加 data-toggle="tooltip"
和 data-trigger="manual"
属性以及 title
,然后通过使用“调用 tooltip() method
从 JS 切换工具提示”切换”作为参数。添加了下面的代码片段:
HTML startdate_datepicker 元素:
<input class="form-control start_date" type="text" placeholder="Start Date" name="startdate_datepicker" id="startdate_datepicker" required="true" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom" data-trigger="manual">
JavaScript:
if (start > end) {
e.preventDefault();
// alert("Stop and tooltip");
$('#startdate_datepicker').tooltip("toggle");
}
答案 2 :(得分:0)
现在您正在为该输入初始化工具提示。您需要在 init 之后手动打开工具提示,如下所示:
$("#startdate_datepicker").tooltip({
content: "Message!"
}).tooltip("open");