使用javascript强制显示引导工具提示
我一直在到处寻找,有没有办法强制显示工具提示,不是使用事件,而是使用js代码,因为我们都知道数字输入和粘贴漏洞的缺陷使用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
<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');
}
});
})