最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Force show bootstrap tooltip using javascript - Stack Overflow

programmeradmin4浏览0评论

I've been looking everywhere, is there any way to force show the tooltip, not using an event, but using a js code, because we all know the flaw of numerical input and the paste exploit.

<script type="text/javascript">
var previous;
//Buy Button JS code
$(function () {
    $("#searchform").bind('submit', function () {
        var str = $('#search-form').val();
        if (str.match(/^[0-9]*$/)) {
            //Great, continue executing the script.
        }
        else
        {
            //Force show a tooltip asking the user to numerically type the text.
        }
    });
});

I've been looking everywhere, is there any way to force show the tooltip, not using an event, but using a js code, because we all know the flaw of numerical input and the paste exploit.

<script type="text/javascript">
var previous;
//Buy Button JS code
$(function () {
    $("#searchform").bind('submit', function () {
        var str = $('#search-form').val();
        if (str.match(/^[0-9]*$/)) {
            //Great, continue executing the script.
        }
        else
        {
            //Force show a tooltip asking the user to numerically type the text.
        }
    });
});

Share Improve this question asked Mar 29, 2016 at 19:12 OmarrrioOmarrrio 1,1421 gold badge16 silver badges34 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 11

To trigger a tooltip to show up you need to use the 'show' option of the tooltip. Here is an example.

$('#element').tooltip('show')

Replace #element with your own selector.

To add title using Jquery itself you can do this

$('#element').tooltip({title:"test title"})

To show tooltip

$('#youtooltip').tooltip('show');

Your code:

var previous;
//Buy Button JS code
$(function () {
    $("#searchform").bind('submit', function () {
        var str = $('#search-form').val();
        if (str.match(/^[0-9]*$/)) {
            //Great, continue executing the script.
        }
        else
        {
            $('#youtooltipid').tooltip('show');
            // or $('.youtooltipclass').tooltip('show');
        }
    });
})

try

$('[data-toggle="tooltip"]').tooltip()
发布评论

评论列表(0)

  1. 暂无评论