使用JavaScript强制显示Bootstrap提示框

6

我一直在寻找方法,是否有办法通过js代码强制显示提示框,而不是使用事件触发,因为我们都知道数字输入和粘贴漏洞的缺陷。

<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.
        }
    });
});

3个回答

11

要触发提示框的显示,您需要使用提示框的选项'show'。这里是一个例子。

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

用您自己的选择器替换#element

要使用Jquery自身添加标题,可以这样做

$('#element').tooltip({title:"测试标题"})


1
谢谢,你回答了两个问题 :) - Omarrrio

3

显示提示信息

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

你的代码:

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

1
尝试
$('[data-toggle="tooltip"]').tooltip()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接