仅当输入val长度<n时,BOOTSTRAP才会在输入元素上触发工具提示

its*_*sme 4 javascript jquery input tooltip twitter-bootstrap

我想显示工具提示,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');

   }
  });
Run Code Online (Sandbox Code Playgroud)

它显然不起作用:/

Vis*_*ioN 8

从理论上讲,它应该工作:

$("#nav-search").on("keyup", function() {
    if (this.value.length <= 3) {
        $(this).tooltip("show");
    } else {
        $(this).tooltip("hide");
    }
}).tooltip({
    placement: "right",
    trigger: "focus"
});?
Run Code Online (Sandbox Code Playgroud)

实际上,它有效.

演示: http ://jsfiddle.net/FvxnN/