当前位置: 首页 > 面试题库 >

是否有用于文本字段的jQuery自动增长插件?

申屠涛
2023-03-14
问题内容

我找到了各种用于自动增长 textarea的 插件,但没有输入文本字段。有人知道是否存在吗?


问题答案:

这是一个插件,可以满足您的需求:

编辑 :我已经按照Mathias的评论修复了插件。:)

插件:

(function($){

    $.fn.autoGrowInput = function(o) {

        o = $.extend({
            maxWidth: 1000,
            minWidth: 0,
            comfortZone: 70
        }, o);

        this.filter('input:text').each(function(){

            var minWidth = o.minWidth || $(this).width(),
                val = '',
                input = $(this),
                testSubject = $('<tester/>').css({
                    position: 'absolute',
                    top: -9999,
                    left: -9999,
                    width: 'auto',
                    fontSize: input.css('fontSize'),
                    fontFamily: input.css('fontFamily'),
                    fontWeight: input.css('fontWeight'),
                    letterSpacing: input.css('letterSpacing'),
                    whiteSpace: 'nowrap'
                }),
                check = function() {

                    if (val === (val = input.val())) {return;}

                    // Enter new content into testSubject
                    var escaped = val.replace(/&/g, '&amp;').replace(/\s/g,'&nbsp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
                    testSubject.html(escaped);

                    // Calculate new width + whether to change
                    var testerWidth = testSubject.width(),
                        newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth,
                        currentWidth = input.width(),
                        isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth)
                                             || (newWidth > minWidth && newWidth < o.maxWidth);

                    // Animate width
                    if (isValidWidthChange) {
                        input.width(newWidth);
                    }

                };

            testSubject.insertAfter(input);

            $(this).bind('keyup keydown blur update', check);

        });

        return this;

    };

})(jQuery);


 类似资料:
  • 我试图在表中插入一行,带有一个自动递增字段,但我遇到了错误。该表的结构为: id:自动增量 级别:文本 概念:文本 . 在w3c中,我了解到要将新记录插入表中,我们不必为“自动增量”列指定值(将自动添加唯一值)。 我做错了什么?

  • 本文向大家介绍MyBatis获取插入记录的自增长字段值(ID),包括了MyBatis获取插入记录的自增长字段值(ID)的使用技巧和注意事项,需要的朋友参考一下 第一步:     在Mybatis Mapper文件中添加属性“useGeneratedKeys”和“keyProperty”,其中keyProperty是Java对象的属性名! 第二步:     Mybatis执行完插入语句后,自动将自增

  • 主要内容:使用 counters 集合,创建 Javascript 函数,使用 Javascript 函数MongoDB 中没有像 SQL 中那样可以赋予某个字段自动递增的功能,默认情况下 MongoDB 的 _id 字段是系统自动生成的 12 字节的唯一标识,但是在某些情况下我们可能需要在 MongoDB 的某个字段上实现类似 SQL 中的自动递增功能。 因为 MongoDB 中没有实现这个功能,所以我们需要通过编程的方式来实现。本节中我们将通过两个集合(counters 和 tutorial

  • 字段自增 const flow = await this.ctx.model.Flow.findOne({ where: { art_id } }); await flow.increment('index', { by: 900 }); 字段自减 const flow = await this.ctx.model.Flow.findOne({ where: { art_id } }); awai

  • 问题内容: 我需要在MySQL表中插入包含32个字段的长行。 我想做这样的事情: 显然,如果字段与MySQL表字段的顺序相同,则可以正常工作。但是,我的表的第一个字段具有自动递增的ID。 我想要的是填写除第一个(id)以外的所有表名。 有什么建议吗? 问题答案: 仅用作您的第一个值,该字段仍将按预期工作:

  • 本文向大家介绍mongodb字段值自增长实现代码,包括了mongodb字段值自增长实现代码的使用技巧和注意事项,需要的朋友参考一下 MongoDB 没有像 SQL 一样有自动增长的功能, MongoDB 的 _id 是系统自动生成的12字节唯一标识。但在某些情况下,我们可能需要实现 ObjectId 自动增长功能。由于 MongoDB 没有实现这个功能,我们可以通过编程的方式来实现,以下我们将在