Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript强制显示引导工具提示_Javascript_Jquery_Twitter Bootstrap - Fatal编程技术网

使用javascript强制显示引导工具提示

使用javascript强制显示引导工具提示,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我一直在到处寻找,有没有办法强制显示工具提示,不是使用事件,而是使用js代码,因为我们都知道数字输入和粘贴漏洞的缺陷 <script type="text/javascript"> var previous; //Buy Button JS code $(function () { $("#searchform").bind('submit', function () { var str = $('#search-form').val(); i

我一直在到处寻找,有没有办法强制显示工具提示,不是使用事件,而是使用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.
        }
    });
});

var-previous;
//购买按钮JS代码
$(函数(){
$(“#searchform”).bind('submit',函数(){
var str=$(“#搜索表单”).val();
如果(str.match(/^[0-9]*$/){
//很好,继续执行脚本。
}
其他的
{
//强制显示工具提示,要求用户以数字形式键入文本。
}
});
});
试试看

显示工具提示的步骤

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

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

$('#元素')。工具提示('show')

用您自己的选择器替换
#元素

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


$(“#元素”)。工具提示({title:“test title”})

谢谢,您回答了这两个问题:)
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');
        }
    });
})