繁体   English   中英

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

[英]Jquery UI tooltip doesn't show on anything

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

这是我到目前为止所拥有的:

http://jsfiddle.net/k84phas6/

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

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

有任何想法吗?

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

  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')
  }

startdate_datepicker元素上添加data-toggle="tooltip"data-trigger="manual"属性以及title ,然后通过以“toggle”为参数调用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");
}

找到小提琴代码

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM