我想在 input.val().length <= 3
时显示工具提示然后在 > 3 个字符时隐藏工具提示
检查一下:
<input type="text" id="nav-search"/>
$('#nav-search').on('keyup',function(){
var _keys = $(this).val();
if(_keys.length <= 3){
$(this).tooltip({'trigger':'focus',position:'right'});
$(this).trigger('focusin');
}
});
它显然不起作用:/
最佳答案
理论上,它应该有效:
$("#nav-search").on("keyup", function() {
if (this.value.length <= 3) {
$(this).tooltip("show");
} else {
$(this).tooltip("hide");
}
}).tooltip({
placement: "right",
trigger: "focus"
});
实际上,它是有效的。
关于javascript - 仅当输入值长度 < n 时,BOOTSTRAP 在输入元素上触发工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12581086/