Jquery UI 工具提示不显示任何内容

时间:2021-05-06 09:46:29

标签: javascript jquery twitter-bootstrap bootstrap-datepicker jquery-ui-tooltip

我正在使用 2 个引导日期选择器和 我想验证开始日期是否大于结束日期然后显示工具提示

这是我目前所拥有的:

http://jsfiddle.net/k84phas6/

$('#startdate_datepicker').tooltip({ content : "Example"});

警报出现了,但工具提示没有做任何事情,我不明白为什么。

有什么想法吗?

3 个答案:

答案 0 :(得分:2)

刚刚检查了您的小提琴,您必须在多个地方进行更改。

  1. 从输入框中删除 title="" 字段。这与引导程序使用的工具提示的标题字段相冲突。
  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");
}

找到fiddle code

答案 2 :(得分:0)

现在您正在为该输入初始化工具提示。您需要在 init 之后手动打开工具提示,如下所示:

$("#startdate_datepicker").tooltip({
   content: "Message!"
}).tooltip("open");