代码之家  ›  专栏  ›  技术社区  ›  Kjensen

JQuery表单工具提示

  •  1
  • Kjensen  · 技术社区  · 16 年前

    ,大致如下:

    alt text

    因此,每个表单字段都有一个关联的提示文本,该提示文本显示在焦点上。

    在html/javascript中链接此内容的内容:

    <input type="text" id="VIN" name="VIN" class="tooltipped">
    
    <label for="VIN" class="formfieldtooltip">A vehicle Iden... </label>
    
    <input type="text" id="Brand" name="Brand" class="tooltipped">
    
    <label for="Brand" class="formfieldtooltip">In Danish "brand" means "fire"</label>
    
    <script type="text/javascript">
    
        jQuery(function($) {
    
            $(".tooltipped").FormFieldToolTipBinder();
    
        });
    
    </script>
    

    这样的东西已经存在了,还是我必须自己写?

    是的,我在谷歌上找到了很多插件来制作实际的工具提示,但是没有一个能像这样自动将它们与表单字段连接起来。

    2 回复  |  直到 7 年前
        1
  •  5
  •   Jeff Sternal    16 年前

    听起来您可能无法将工具提示内容嵌入到 label alt 你的个性 input 元素, you can do what you want with qTip ,例如:

    <input type="text" id="VIN" class="tooltipped" alt="A vehicle iden...">
    

    和

    // content: false tells qtip to use the selected elements' alt text
    $('.tooltipped').qtip({
        content: false,
        show: { when: { event: 'focus' } }
    });
    
        2
  •  1
  •   fredrik    16 年前

    事实上,你自己写很容易。以下是一些让您开始学习的内容:

    var tooltip = function (formElementId) {
        var form = $('#' + formElementId),
            toolTipClass = 'tooltip',
            input = form.find('input.'+ tooltip);
    
        input.each(function (index, elem) {
            $(elem).focus(function () {
                $(this).parent().append('<div id="tooltip"></div>');
            })
    
            $(elem).blur(function () {
                $('#tooltip').remove();
            })
        });
    }