【问题标题】:BOOTSTRAP trigger tooltip on input element only if input val length < n仅当输入 val 长度 < n 时,输入元素上的 BOOTSTRAP 触发工具提示
【发布时间】:2012-09-25 10:30:13
【问题描述】:

我想在input.val().length &lt;= 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');

   }
  });

它显然不起作用:/

【问题讨论】:

    标签: javascript jquery input twitter-bootstrap tooltip


    【解决方案1】:

    理论上,它应该可以工作:

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

    实际上,它有效。

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

    【讨论】:

    • 当焦点和长度 3 时如何在 keyup 上隐藏它?谢谢你,你会是答案!
    • 因为现在只有 keyup 事件,工具提示“闪烁”直到 4 个字符,我不想闪烁(隐藏/显示 + 隐藏/显示 + 隐藏/显示)
    • 两个小提琴都停止工作,因为 Bootstrap 移动了他们的文件。我更新了this fiddle 中的参考资料。感谢您的简单示例!
    【解决方案2】:
    $('#nav-search').bind('keyup',function(){
       var _keys = $(this).val();
       if(_keys.length <= 3){
       $(this).tooltip({'trigger':'focus',position:'right'});
       $(this).trigger('focusin');
    
       }else{
    
      //perform some action
      }
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      相关资源
      最近更新 更多